Skip to content

Commit c5c56f1

Browse files
committed
Initialize vault and load it with 1029$
1 parent caf69bc commit c5c56f1

File tree

18 files changed

+261
-175
lines changed

18 files changed

+261
-175
lines changed

basics/pda-rent-payer/steel/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ keywords = ["solana"]
1414

1515
[workspace.dependencies]
1616
pda-rent-payer-api = { path = "./api", version = "0.1.0" }
17+
borsh = "1.5"
1718
bytemuck = "1.14"
1819
num_enum = "0.7"
1920
solana-program = "1.18"

basics/pda-rent-payer/steel/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# Steel
1+
# PDA Rent Payer
22

3-
**Steel** is a ...
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
45

56
## API
67
- [`Consts`](api/src/consts.rs) – Program constants.
78
- [`Error`](api/src/error.rs) – Custom program errors.
8-
- [`Event`](api/src/event.rs) – Custom program events.
99
- [`Instruction`](api/src/instruction.rs) – Declared instructions.
1010

1111
## Instructions

basics/pda-rent-payer/steel/api/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ readme.workspace = true
1111
keywords.workspace = true
1212

1313
[dependencies]
14+
borsh.workspace = true
1415
bytemuck.workspace = true
1516
num_enum.workspace = true
1617
solana-program.workspace = true

basics/pda-rent-payer/steel/api/src/instruction.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use borsh::{ BorshDeserialize, BorshSerialize };
12
use steel::*;
23

34
#[repr(u8)]
@@ -8,7 +9,7 @@ pub enum PdaRentPayerInstruction {
89
}
910

1011
#[repr(C)]
11-
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
12+
#[derive(BorshSerialize, BorshDeserialize, Clone, Copy, Debug, Pod, Zeroable)]
1213
pub struct InitializeRentVault {
1314
pub amount: u64,
1415
}

basics/pda-rent-payer/steel/api/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ pub mod prelude {
1515
use steel::*;
1616

1717
// TODO Set program id
18-
declare_id!("H8ocBhDZmzxRvWnT1yu5EQyLN3D9AYZv9qsePcx8pidg");
18+
declare_id!("HK5TuboXztZv7anSa3GptyCZ5wMYiqbY8kNSVEtqWDuD");

basics/pda-rent-payer/steel/api/src/sdk.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@ use steel::*;
22

33
use crate::prelude::*;
44

5-
pub fn init_rent_vault(signer_info: Pubkey, system_program: Pubkey, data: &[u8]) -> Instruction {
5+
pub fn init_rent_vault(signer_info: Pubkey, system_program: Pubkey, amount: u64) -> Instruction {
66
Instruction {
77
program_id: crate::ID,
88
accounts: vec![
99
AccountMeta::new(signer_info, true),
1010
AccountMeta::new(rent_vault_pda().0, false),
1111
AccountMeta::new_readonly(system_program, false),
1212
],
13-
data: InitializeRentVault {
14-
amount: u64::from_be_bytes(data[..8].try_into().unwrap()),
15-
}
16-
.to_bytes(),
13+
data: InitializeRentVault { amount }.to_bytes(),
1714
}
1815
}
1916

@@ -23,7 +20,6 @@ pub fn create_new_account(rent_vault: Pubkey, new_account: Pubkey) -> Instructio
2320
accounts: vec![
2421
AccountMeta::new(rent_vault, false),
2522
AccountMeta::new(new_account, true),
26-
AccountMeta::new_readonly(system_program::ID, false),
2723
],
2824
data: CreateNewAccount {}.to_bytes(),
2925
}

basics/pda-rent-payer/steel/api/src/state/accounts.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::PdaRentPayerAccount;
1+
use super::PdaRentPayerAccountDiscriminator;
22
use steel::*;
33

44
/// This empty struct represents the payer vault account
@@ -12,5 +12,5 @@ pub struct RentVault {}
1212
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
1313
pub struct NewAccount {}
1414

15-
account!(PdaRentPayerAccount, RentVault);
16-
account!(PdaRentPayerAccount, NewAccount);
15+
account!(PdaRentPayerAccountDiscriminator, RentVault);
16+
account!(PdaRentPayerAccountDiscriminator, NewAccount);

basics/pda-rent-payer/steel/api/src/state/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use steel::*;
88
/// accounts this program can interact with
99
#[repr(u8)]
1010
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
11-
pub enum PdaRentPayerAccount {
11+
pub enum PdaRentPayerAccountDiscriminator {
1212
RentVault = 0,
1313
NewAccount = 1,
1414
}
@@ -17,8 +17,3 @@ pub enum PdaRentPayerAccount {
1717
pub fn rent_vault_pda() -> (Pubkey, u8) {
1818
Pubkey::find_program_address(&[RENT_VAULT], &crate::id())
1919
}
20-
21-
// Fetch PDA of the newly_created account.
22-
// pub fn new_account_pda() -> (Pubkey, u8) {
23-
// Pubkey::find_program_address(&[NEW_ACCOUNT], &crate::id())
24-
// }
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
# Buld and deploy this program with ease using a single command
4+
# Run this script with "bash cicd.sh" or "./cicd.sh"
5+
# Note: Try running "chmod +x cicd.sh" if you face any issues.
6+
7+
# Check if cargo is installed
8+
if ! command -v cargo &> /dev/null
9+
then
10+
echo "Cargo could not be found. Please install Rust."
11+
exit 1
12+
fi
13+
14+
# Check if solana CLI is installed
15+
if ! command -v solana &> /dev/null
16+
then
17+
echo "Solana CLI could not be found. Please install Solana."
18+
exit 1
19+
fi
20+
21+
22+
# Build
23+
cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so
24+
25+
# Deploy
26+
solana program deploy ./program/target/so/pda_rent_payer_program.so

basics/pda-rent-payer/steel/package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
"type": "module",
55
"description": "Use a PDA to pay the rent for the creation of a new account.",
66
"scripts": {
7-
"test": "pnpm ts-mocha -p ./tsconfig.json -t 1000000 ./tests/test.ts",
7+
"test": "pnpm ts-mocha -p ./tsconfig.json -t 1000000 ./tests/*.test.ts",
88
"build-and-test": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./tests/fixtures && pnpm test",
99
"build": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so",
1010
"deploy": "solana program deploy ./program/target/so/pda_rent_payer_program.so"
1111
},
12-
"keywords": [
13-
"solana"
14-
],
12+
"keywords": ["solana"],
1513
"author": "",
1614
"license": "MIT",
1715
"dependencies": {
@@ -20,9 +18,10 @@
2018
"devDependencies": {
2119
"@types/chai": "^4.3.20",
2220
"@types/mocha": "^10.0.9",
23-
"@types/node": "^22.8.2",
21+
"@types/node": "^22.8.5",
22+
"borsh": "^2.0.0",
2423
"chai": "^4.5.0",
25-
"mocha": "^10.7.3",
24+
"mocha": "^10.8.2",
2625
"solana-bankrun": "^0.4.0",
2726
"ts-mocha": "^10.0.0",
2827
"typescript": "^5.6.3"

0 commit comments

Comments
 (0)