Skip to content

Commit

Permalink
add basics/transfer-sol/steel (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
onspeedhp authored Jan 2, 2025
1 parent 6ef5655 commit adee195
Show file tree
Hide file tree
Showing 17 changed files with 1,875 additions and 0 deletions.
21 changes: 21 additions & 0 deletions basics/transfer-sol/steel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[workspace]
resolver = "2"
members = ["api", "program"]

[workspace.package]
version = "0.1.0"
edition = "2021"
license = "Apache-2.0"
homepage = ""
documentation = ""
repository = ""
readme = "./README.md"
keywords = ["solana"]

[workspace.dependencies]
transfer-sol-api = { path = "./api", version = "0.1.0" }
bytemuck = "1.14"
num_enum = "0.7"
solana-program = "1.18"
steel = "1.3"
thiserror = "1.0"
22 changes: 22 additions & 0 deletions basics/transfer-sol/steel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# TransferSol

**TransferSol** is a ...

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

## Instructions
- [`Hello`](program/src/hello.rs) – Hello ...

## State
- [`User`](api/src/state/user.rs) – User ...

## Tests

To run the test suit, use the Solana toolchain:
```
cargo test-sbf
```
11 changes: 11 additions & 0 deletions basics/transfer-sol/steel/api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "transfer-sol-api"
version = "0.1.0"
edition = "2021"

[dependencies]
bytemuck.workspace = true
num_enum.workspace = true
solana-program.workspace = true
steel.workspace = true
thiserror.workspace = true
24 changes: 24 additions & 0 deletions basics/transfer-sol/steel/api/src/instruction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use steel::*;

#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
pub enum TransferSolInstruction {
TransferSolWithCpi = 0,
TransferSolWithProgram = 1,
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct TransferSolWithCpi {
pub amount: [u8; 8],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct TransferSolWithProgram {
pub amount: [u8; 8],
}

instruction!(TransferSolInstruction, TransferSolWithCpi);
instruction!(TransferSolInstruction, TransferSolWithProgram);

12 changes: 12 additions & 0 deletions basics/transfer-sol/steel/api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pub mod instruction;
pub mod sdk;

pub mod prelude {
pub use crate::instruction::*;
pub use crate::sdk::*;
}

use steel::*;

// TODO: Set program id
declare_id!("FNDnd3ZJptKromzx7h71o67AcR1emryyJPb9LjS8WPVw");
32 changes: 32 additions & 0 deletions basics/transfer-sol/steel/api/src/sdk.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use steel::*;

use crate::prelude::*;

pub fn transfer_sol_with_cpi(signer: Pubkey, receiver: Pubkey, amount: u64) -> Instruction {
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(receiver, false),
AccountMeta::new(system_program::ID, false),
],
data: TransferSolWithCpi {
amount: amount.to_le_bytes(),
}
.to_bytes(),
}
}

pub fn transfer_sol_with_program(signer: Pubkey, receiver: Pubkey, amount: u64) -> Instruction {
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(receiver, false),
],
data: TransferSolWithProgram {
amount: amount.to_le_bytes(),
}
.to_bytes(),
}
}
8 changes: 8 additions & 0 deletions basics/transfer-sol/steel/cicd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# This script is for quick building & deploying of the program.
# It also serves as a reference for the commands used for building & deploying Solana programs.
# Run this bad boy with "bash cicd.sh" or "./cicd.sh"

cargo build-sbf --manifest-path=./program/Cargo.toml --bpf-out-dir=./program/target/so
solana program deploy ./program/target/so/program.so
26 changes: 26 additions & 0 deletions basics/transfer-sol/steel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"scripts": {
"test": "steel test",
"build-and-test": "steel build && steel test",
"build": "steel build",
"deploy": "solana program deploy ./program/target/so/program.so",
"check:fix": "pnpm biome format --write ./tests",
"rust:test": "cargo test-sbf"
},
"dependencies": {
"@solana/web3.js": "^1.47.3",
"buffer-layout": "^1.2.2",
"fs": "^0.0.1-security"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.1",
"@types/mocha": "^9.1.1",
"chai": "^4.3.4",
"mocha": "^10.7.3",
"solana-bankrun": "^0.3.0",
"ts-mocha": "^10.0.0",
"typescript": "^5.6.3"
}
}
Loading

0 comments on commit adee195

Please sign in to comment.