Skip to content

Commit 123c289

Browse files
authored
add basics/pda-rent-payer/steel (#293)
1 parent 82a68b3 commit 123c289

File tree

20 files changed

+1800
-0
lines changed

20 files changed

+1800
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target
2+
test-ledger
3+
node_modules
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[workspace]
2+
resolver = "2"
3+
members = ["api", "program"]
4+
5+
[workspace.package]
6+
version = "0.1.0"
7+
edition = "2021"
8+
license = "Apache-2.0"
9+
homepage = ""
10+
documentation = ""
11+
repository = ""
12+
readme = "./README.md"
13+
keywords = ["solana"]
14+
15+
[workspace.dependencies]
16+
pda-rent-payer-api = { path = "./api", version = "0.1.0" }
17+
borsh = "1.5"
18+
bytemuck = "1.14"
19+
num_enum = "0.7"
20+
solana-program = "1.18"
21+
steel = "2.1"
22+
thiserror = "1.0"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# PDA Rent Payer
2+
3+
**PDA Rent Payer** is a program that uses a PDA to pay the rent
4+
for the creation of a system program by simply transferring lamports to it
5+
6+
## API
7+
- [`Consts`](api/src/consts.rs) – Program constants.
8+
- [`Error`](api/src/error.rs) – Custom program errors.
9+
- [`Instruction`](api/src/instruction.rs) – Declared instructions.
10+
11+
## Instructions
12+
- [`Add`](program/src/add.rs) – Add ...
13+
- [`Initialize`](program/src/initialize.rs) – Initialize ...
14+
15+
## State
16+
- [`Counter`](api/src/state/counter.rs) – Counter ...
17+
18+
## Get started
19+
20+
Compile your program:
21+
```sh
22+
steel build
23+
```
24+
25+
Run unit and integration tests:
26+
```sh
27+
steel test
28+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "pda-rent-payer-api"
3+
description = "API for interacting with the PDA rent payer program"
4+
version.workspace = true
5+
edition.workspace = true
6+
license.workspace = true
7+
homepage.workspace = true
8+
documentation.workspace = true
9+
repository.workspace = true
10+
readme.workspace = true
11+
keywords.workspace = true
12+
13+
[dependencies]
14+
borsh.workspace = true
15+
bytemuck.workspace = true
16+
num_enum.workspace = true
17+
solana-program.workspace = true
18+
steel.workspace = true
19+
thiserror.workspace = true
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Seed of the rent vault account PDA.
2+
pub const RENT_VAULT: &[u8] = b"rent_vault";
3+
4+
// Seed of the account PDA to be created.
5+
// pub const NEW_ACCOUNT: &[u8] = b"new_account";
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use steel::*;
2+
3+
#[derive(Debug, Error, Clone, Copy, PartialEq, Eq, IntoPrimitive)]
4+
#[repr(u32)]
5+
pub enum PdaRentPayerError {
6+
#[error("Rent vault account already initialized")]
7+
RentVaultInitialized = 0,
8+
}
9+
10+
error!(PdaRentPayerError);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use borsh::{BorshDeserialize, BorshSerialize};
2+
use steel::*;
3+
4+
#[repr(u8)]
5+
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
6+
pub enum PdaRentPayerInstruction {
7+
InitializeRentVault = 0,
8+
CreateNewAccount = 1,
9+
}
10+
11+
#[repr(C)]
12+
#[derive(BorshSerialize, BorshDeserialize, Clone, Copy, Debug, Pod, Zeroable)]
13+
pub struct InitializeRentVault {
14+
pub amount: u64,
15+
}
16+
17+
#[repr(C)]
18+
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
19+
pub struct CreateNewAccount {}
20+
21+
instruction!(PdaRentPayerInstruction, InitializeRentVault);
22+
instruction!(PdaRentPayerInstruction, CreateNewAccount);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
pub mod consts;
2+
pub mod error;
3+
pub mod instruction;
4+
pub mod sdk;
5+
pub mod state;
6+
7+
pub mod prelude {
8+
pub use crate::consts::*;
9+
pub use crate::error::*;
10+
pub use crate::instruction::*;
11+
pub use crate::sdk::*;
12+
pub use crate::state::*;
13+
}
14+
15+
use steel::*;
16+
17+
// TODO Set program id
18+
declare_id!("HK5TuboXztZv7anSa3GptyCZ5wMYiqbY8kNSVEtqWDuD");
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use steel::*;
2+
3+
use crate::prelude::*;
4+
5+
pub fn init_rent_vault(signer_info: Pubkey, system_program: Pubkey, amount: u64) -> Instruction {
6+
Instruction {
7+
program_id: crate::ID,
8+
accounts: vec![
9+
AccountMeta::new(signer_info, true),
10+
AccountMeta::new(rent_vault_pda().0, false),
11+
AccountMeta::new_readonly(system_program, false),
12+
],
13+
data: InitializeRentVault { amount }.to_bytes(),
14+
}
15+
}
16+
17+
pub fn create_new_account(rent_vault: Pubkey, new_account: Pubkey) -> Instruction {
18+
Instruction {
19+
program_id: crate::ID,
20+
accounts: vec![
21+
AccountMeta::new(rent_vault, false),
22+
AccountMeta::new(new_account, true),
23+
],
24+
data: CreateNewAccount {}.to_bytes(),
25+
}
26+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use super::PdaRentPayerAccountDiscriminator;
2+
use steel::*;
3+
4+
/// This empty struct represents the payer vault account
5+
#[repr(C)]
6+
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
7+
pub struct RentVault {}
8+
9+
/// This empty struct represents the account
10+
/// that the vault will pay for
11+
#[repr(C)]
12+
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
13+
pub struct NewAccount {}
14+
15+
account!(PdaRentPayerAccountDiscriminator, RentVault);
16+
account!(PdaRentPayerAccountDiscriminator, NewAccount);

0 commit comments

Comments
 (0)