Skip to content

Commit adee195

Browse files
authored
add basics/transfer-sol/steel (#201)
1 parent 6ef5655 commit adee195

File tree

17 files changed

+1875
-0
lines changed

17 files changed

+1875
-0
lines changed

basics/transfer-sol/steel/Cargo.toml

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+
transfer-sol-api = { path = "./api", version = "0.1.0" }
17+
bytemuck = "1.14"
18+
num_enum = "0.7"
19+
solana-program = "1.18"
20+
steel = "1.3"
21+
thiserror = "1.0"

basics/transfer-sol/steel/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# TransferSol
2+
3+
**TransferSol** 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+
- [`Hello`](program/src/hello.rs) – Hello ...
13+
14+
## State
15+
- [`User`](api/src/state/user.rs) – User ...
16+
17+
## Tests
18+
19+
To run the test suit, use the Solana toolchain:
20+
```
21+
cargo test-sbf
22+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "transfer-sol-api"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
bytemuck.workspace = true
8+
num_enum.workspace = true
9+
solana-program.workspace = true
10+
steel.workspace = true
11+
thiserror.workspace = true
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use steel::*;
2+
3+
#[repr(u8)]
4+
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
5+
pub enum TransferSolInstruction {
6+
TransferSolWithCpi = 0,
7+
TransferSolWithProgram = 1,
8+
}
9+
10+
#[repr(C)]
11+
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
12+
pub struct TransferSolWithCpi {
13+
pub amount: [u8; 8],
14+
}
15+
16+
#[repr(C)]
17+
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
18+
pub struct TransferSolWithProgram {
19+
pub amount: [u8; 8],
20+
}
21+
22+
instruction!(TransferSolInstruction, TransferSolWithCpi);
23+
instruction!(TransferSolInstruction, TransferSolWithProgram);
24+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
pub mod instruction;
2+
pub mod sdk;
3+
4+
pub mod prelude {
5+
pub use crate::instruction::*;
6+
pub use crate::sdk::*;
7+
}
8+
9+
use steel::*;
10+
11+
// TODO: Set program id
12+
declare_id!("FNDnd3ZJptKromzx7h71o67AcR1emryyJPb9LjS8WPVw");
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use steel::*;
2+
3+
use crate::prelude::*;
4+
5+
pub fn transfer_sol_with_cpi(signer: Pubkey, receiver: Pubkey, amount: u64) -> Instruction {
6+
Instruction {
7+
program_id: crate::ID,
8+
accounts: vec![
9+
AccountMeta::new(signer, true),
10+
AccountMeta::new(receiver, false),
11+
AccountMeta::new(system_program::ID, false),
12+
],
13+
data: TransferSolWithCpi {
14+
amount: amount.to_le_bytes(),
15+
}
16+
.to_bytes(),
17+
}
18+
}
19+
20+
pub fn transfer_sol_with_program(signer: Pubkey, receiver: Pubkey, amount: u64) -> Instruction {
21+
Instruction {
22+
program_id: crate::ID,
23+
accounts: vec![
24+
AccountMeta::new(signer, true),
25+
AccountMeta::new(receiver, false),
26+
],
27+
data: TransferSolWithProgram {
28+
amount: amount.to_le_bytes(),
29+
}
30+
.to_bytes(),
31+
}
32+
}

basics/transfer-sol/steel/cicd.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
# This script is for quick building & deploying of the program.
4+
# It also serves as a reference for the commands used for building & deploying Solana programs.
5+
# Run this bad boy with "bash cicd.sh" or "./cicd.sh"
6+
7+
cargo build-sbf --manifest-path=./program/Cargo.toml --bpf-out-dir=./program/target/so
8+
solana program deploy ./program/target/so/program.so
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"scripts": {
3+
"test": "steel test",
4+
"build-and-test": "steel build && steel test",
5+
"build": "steel build",
6+
"deploy": "solana program deploy ./program/target/so/program.so",
7+
"check:fix": "pnpm biome format --write ./tests",
8+
"rust:test": "cargo test-sbf"
9+
},
10+
"dependencies": {
11+
"@solana/web3.js": "^1.47.3",
12+
"buffer-layout": "^1.2.2",
13+
"fs": "^0.0.1-security"
14+
},
15+
"devDependencies": {
16+
"@biomejs/biome": "1.9.4",
17+
"@types/bn.js": "^5.1.0",
18+
"@types/chai": "^4.3.1",
19+
"@types/mocha": "^9.1.1",
20+
"chai": "^4.3.4",
21+
"mocha": "^10.7.3",
22+
"solana-bankrun": "^0.3.0",
23+
"ts-mocha": "^10.0.0",
24+
"typescript": "^5.6.3"
25+
}
26+
}

0 commit comments

Comments
 (0)