Skip to content
22 changes: 22 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# soroban-sdk-nexus 🚀

Soroban SDK Nexus adalah fork dari rs-soroban-sdk yang difokuskan pada:
- 🔗 Interoperabilitas lintas jaringan
- 🛡️ Pola keamanan kontrak pintar
- 🧠 Tooling analisis kontrak
- 📚 Edukasi & contoh siap pakai

Cocok untuk developer yang ingin membangun DeFi, DAO, dan aplikasi terdesentralisasi di Soroban dengan standar enterprise.

## Fitur Utama
- Nexus Interop Layer
- Secure Smart Contract Patterns
- DeFi & DAO Examples
- Gas Optimizer & Risk Scorer
- Dokumentasi Bahasa Indonesia 🇮🇩

## Quick Start
```bash
git clone https://github.com/USERNAME/soroban-sdk-nexus
cd soroban-sdk-nexus
cargo test
20 changes: 20 additions & 0 deletions secure-patterns/access-control.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use soroban_sdk::{contracttype, Address, Env, Map};

#[contracttype]
#[derive(Clone)]
pub struct Roles {
pub admin: Address,
pub operators: Map<Address, bool>,
}

pub fn only_admin(e: &Env, roles: &Roles, caller: &Address) {
if &roles.admin != caller {
panic!("Not authorized: Admin only");
}
}

pub fn only_operator(e: &Env, roles: &Roles, caller: &Address) {
if roles.operators.get(caller.clone()).unwrap_or(false) != true {
panic!("Not authorized: Operator only");
}
}
24 changes: 24 additions & 0 deletions secure-patterns/reentrancy-guard.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use soroban_sdk::{contracttype, Env};

#[contracttype]
#[derive(Clone)]
pub struct ReentrancyGuard {
locked: bool,
}

impl ReentrancyGuard {
pub fn new() -> Self {
Self { locked: false }
}

pub fn enter(&mut self) {
if self.locked {
panic!("Reentrancy detected");
}
self.locked = true;
}

pub fn exit(&mut self) {
self.locked = false;
}
}
10 changes: 10 additions & 0 deletions secure-patterns/secure-patterns/nexus-interop/message-format.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use soroban_sdk::{contracttype, Bytes, BytesN};

#[contracttype]
#[derive(Clone)]
pub struct NexusMessage {
pub src_chain: Bytes,
pub dst_chain: Bytes,
pub sender: BytesN<32>,
pub payload: Bytes,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use soroban_sdk::{Env, Address, Bytes};

pub fn emit_bridge_event(e: &Env, from: Address, to_chain: Bytes, payload: Bytes) {
e.events().publish(
(from, to_chain),
payload,
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use soroban_sdk::{Env, Symbol};

pub fn log_gas_usage(e: &Env, tag: Symbol) {
let cpu = e.cost_estimate().cpu_insns;
let mem = e.cost_estimate().mem_bytes;
e.events().publish(tag, (cpu, mem));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use soroban_sdk::{Env, Symbol};

pub fn risk_score(storage_writes: u32, external_calls: u32) -> u32 {
let mut score = 0;
score += storage_writes * 2;
score += external_calls * 5;
score
}

pub fn emit_risk(e: &Env, tag: Symbol, score: u32) {
e.events().publish(tag, score);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Hello Soroban 👋

Contoh kontrak sederhana:

```rust
#[contract]
pub struct Hello;

#[contractimpl]
impl Hello {
pub fn hi(env: Env) -> Symbol {
Symbol::short("hello")
}
}

cargo build --target wasm32-unknown-unknown --release

---

## 🤖 `.github/workflows/ci.yml`

```yaml
name: Soroban Nexus CI

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: Build
run: cargo build --all --release
- name: Test
run: cargo test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use soroban_sdk::{contract, contractimpl, Env, Address, Symbol};

#[contract]
pub struct DaoContract;

#[contractimpl]
impl DaoContract {
pub fn vote(e: Env, voter: Address, proposal: Symbol, support: bool) {
voter.require_auth();
e.events().publish((proposal, voter), support);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use soroban_sdk::{contract, contractimpl, Env, Address};

#[contract]
pub struct StakingContract;

#[contractimpl]
impl StakingContract {
pub fn stake(e: Env, user: Address, amount: i128) {
user.require_auth();
e.events().publish(("stake", user), amount);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use soroban_sdk::{Env, BytesN, Bytes};

pub fn verify_signature(e: &Env, msg: &Bytes, sig: &BytesN<64>, pubkey: &BytesN<32>) -> bool {
e.crypto().ed25519_verify(pubkey, msg, sig)
}
15 changes: 15 additions & 0 deletions secure-patterns/secure-patterns/pausable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use soroban_sdk::{contracttype, Env};

#[contracttype]
#[derive(Clone)]
pub struct PauseState {
pub paused: bool,
}

impl PauseState {
pub fn require_not_paused(&self) {
if self.paused {
panic!("Contract is paused");
}
}
}
27 changes: 27 additions & 0 deletions soroban-sdk-nexus
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
soroban-sdk-nexus/
├── README.md
├── translations/
│ └── id-ID.md
├── examples/
│ ├── defi-staking/
│ ├── dao-governance/
│ ├── escrow/
│ └── nft-market/
├── nexus-interop/
│ ├── message-format.rs
│ ├── signature-verify.rs
│ └── stellar-bridge.rs
├── secure-patterns/
│ ├── access-control.rs
│ ├── reentrancy-guard.rs
│ └── pausable.rs
├── tools/
│ ├── gas-analyzer.rs
│ └── contract-risk-score.rs
├── docs/
│ └── tutorials/
│ ├── 01-hello-soroban.md
│ ├── 02-token.md
│ └── 03-dao.md
└── .github/workflows/
└── ci.yml
Loading