Skip to content

Commit ebb9cbd

Browse files
committed
Complete api and start with program
1 parent 45e302a commit ebb9cbd

File tree

18 files changed

+1596
-0
lines changed

18 files changed

+1596
-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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
bytemuck = "1.14"
18+
num_enum = "0.7"
19+
solana-program = "1.18"
20+
steel = "2.1"
21+
thiserror = "1.0"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Steel
2+
3+
**Steel** is a ...
4+
5+
## API
6+
- [`Consts`](api/src/consts.rs) – Program constants.
7+
- [`Error`](api/src/error.rs) – Custom program errors.
8+
- [`Event`](api/src/event.rs) – Custom program events.
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
bytemuck.workspace = true
15+
num_enum.workspace = true
16+
solana-program.workspace = true
17+
steel.workspace = true
18+
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use steel::*;
2+
3+
#[repr(u8)]
4+
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
5+
pub enum PdaRentPayerInstruction {
6+
InitializeRentVault = 0,
7+
CreateNewAccount = 1
8+
}
9+
10+
#[repr(C)]
11+
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
12+
pub struct InitializeRentVault {
13+
pub fund_lamports: u64,
14+
}
15+
16+
#[repr(C)]
17+
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
18+
pub struct CreateNewAccount {}
19+
20+
instruction!(PdaRentPayerInstruction, InitializeRentVault);
21+
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!("z7msBPQHDJjTvdQRoEcKyENgXDhSRYeHieN1ZMTqo35");
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use steel::*;
2+
3+
use crate::prelude::*;
4+
5+
pub fn initialize(signer: Pubkey) -> Instruction {
6+
Instruction {
7+
program_id: crate::ID,
8+
accounts: vec![
9+
AccountMeta::new(signer, true),
10+
AccountMeta::new(counter_pda().0, false),
11+
AccountMeta::new_readonly(system_program::ID, false),
12+
],
13+
data: Initialize {}.to_bytes()
14+
}
15+
}
16+
17+
pub fn add(signer: Pubkey, amount: u64) -> Instruction {
18+
Instruction {
19+
program_id: crate::ID,
20+
accounts: vec![
21+
AccountMeta::new(signer, true),
22+
AccountMeta::new(counter_pda().0, false),
23+
],
24+
data: Add {
25+
amount: amount.to_le_bytes(),
26+
}
27+
.to_bytes(),
28+
}
29+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use steel::*;
2+
use super::PdaRentPayerAccount;
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!(PdaRentPayerAccount, RentVault);

0 commit comments

Comments
 (0)