Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,20 @@ members = [
"examples/nft-sequential-minting",
"examples/ownable",
"examples/pausable",
"examples/rwa/*",
"examples/rwa/claim-issuer",
"examples/rwa/claim-topics-and-issuers",
"examples/rwa/identity",
"examples/rwa/identity-registry",
"examples/rwa/identity-verifier",
"examples/rwa/token",
"examples/rwa-country-allow",
"examples/rwa-country-restrict",
"examples/rwa-max-balance",
"examples/rwa-supply-limit",
"examples/rwa-time-transfers-limits",
"examples/rwa-transfer-restrict",
"examples/rwa-initial-lockup-period",
"examples/rwa-compliance",
"examples/sac-admin-generic",
"examples/sac-admin-wrapper",
"examples/multisig-smart-account/*",
Expand Down
28 changes: 28 additions & 0 deletions examples/rwa-compliance/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "rwa-compliance-example"
edition.workspace = true
license.workspace = true
repository.workspace = true
publish = false
version.workspace = true

[lib]
crate-type = ["cdylib"]
doctest = false

[dependencies]
soroban-sdk = { workspace = true }
stellar-access = { workspace = true }
stellar-contract-utils = { workspace = true }
stellar-macros = { workspace = true }
stellar-tokens = { workspace = true }

[dev-dependencies]
soroban-sdk = { workspace = true, features = ["testutils"] }
rwa-country-allow = { path = "../rwa-country-allow" }
rwa-country-restrict = { path = "../rwa-country-restrict" }
rwa-initial-lockup-period = { path = "../rwa-initial-lockup-period" }
rwa-max-balance = { path = "../rwa-max-balance" }
rwa-supply-limit = { path = "../rwa-supply-limit" }
rwa-time-transfers-limits = { path = "../rwa-time-transfers-limits" }
rwa-transfer-restrict = { path = "../rwa-transfer-restrict" }
85 changes: 85 additions & 0 deletions examples/rwa-compliance/src/compliance.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//! Compliance dispatcher contract.
//!
//! Implements the `Compliance` trait (which extends `TokenBinder`), routing
//! hook calls to registered compliance modules. All heavy lifting is delegated
//! to the storage helpers in `stellar_tokens::rwa::compliance::storage`.

use soroban_sdk::{contract, contractimpl, symbol_short, Address, Env, Symbol, Vec};
use stellar_access::access_control::{self as access_control, AccessControl};
use stellar_macros::only_role;
use stellar_tokens::rwa::{
compliance::{storage as compliance_storage, Compliance, ComplianceHook},
utils::token_binder::{self as binder, TokenBinder},
};

#[contract]
pub struct ComplianceContract;

#[contractimpl]
impl ComplianceContract {
pub fn __constructor(e: &Env, admin: Address) {
access_control::set_admin(e, &admin);
access_control::grant_role_no_auth(e, &admin, &symbol_short!("admin"), &admin);
}
}

#[contractimpl]
impl Compliance for ComplianceContract {
#[only_role(operator, "admin")]
fn add_module_to(e: &Env, hook: ComplianceHook, module: Address, operator: Address) {
compliance_storage::add_module_to(e, hook, module);
}

#[only_role(operator, "admin")]
fn remove_module_from(e: &Env, hook: ComplianceHook, module: Address, operator: Address) {
compliance_storage::remove_module_from(e, hook, module);
}

fn get_modules_for_hook(e: &Env, hook: ComplianceHook) -> Vec<Address> {
compliance_storage::get_modules_for_hook(e, hook)
}

fn is_module_registered(e: &Env, hook: ComplianceHook, module: Address) -> bool {
compliance_storage::is_module_registered(e, hook, module)
}

fn transferred(e: &Env, from: Address, to: Address, amount: i128, token: Address) {
compliance_storage::transferred(e, from, to, amount, token);
}

fn created(e: &Env, to: Address, amount: i128, token: Address) {
compliance_storage::created(e, to, amount, token);
}

fn destroyed(e: &Env, from: Address, amount: i128, token: Address) {
compliance_storage::destroyed(e, from, amount, token);
}

fn can_transfer(e: &Env, from: Address, to: Address, amount: i128, token: Address) -> bool {
compliance_storage::can_transfer(e, from, to, amount, token)
}

fn can_create(e: &Env, to: Address, amount: i128, token: Address) -> bool {
compliance_storage::can_create(e, to, amount, token)
}
}

#[contractimpl]
impl TokenBinder for ComplianceContract {
fn linked_tokens(e: &Env) -> Vec<Address> {
binder::linked_tokens(e)
}

#[only_role(operator, "admin")]
fn bind_token(e: &Env, token: Address, operator: Address) {
binder::bind_token(e, &token);
}

#[only_role(operator, "admin")]
fn unbind_token(e: &Env, token: Address, operator: Address) {
binder::unbind_token(e, &token);
}
}

#[contractimpl(contracttrait)]
impl AccessControl for ComplianceContract {}
129 changes: 129 additions & 0 deletions examples/rwa-compliance/src/identity_registry.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
//! Identity Registry Storage contract.
//!
//! Provides identity and country-data storage for the RWA compliance stack.
//! Ported from `examples/rwa` with the constructor bug fixed.

use soroban_sdk::{contract, contractimpl, symbol_short, Address, Env, FromVal, IntoVal, Val, Vec};
use stellar_access::access_control::{self as access_control};
use stellar_macros::only_role;
use stellar_tokens::rwa::{
identity_registry_storage::{
self as identity_storage, CountryData, CountryDataManager, IdentityRegistryStorage,
IdentityType,
},
utils::token_binder::{self as binder, TokenBinder},
};

#[contract]
pub struct IdentityRegistryContract;

#[contractimpl]
impl IdentityRegistryContract {
pub fn __constructor(e: &Env, admin: Address, manager: Address) {
access_control::set_admin(e, &admin);
access_control::grant_role_no_auth(e, &manager, &symbol_short!("manager"), &admin);
}

#[only_role(operator, "manager")]
pub fn bind_tokens(e: &Env, tokens: Vec<Address>, operator: Address) {
binder::bind_tokens(e, &tokens);
}
}

#[contractimpl]
impl TokenBinder for IdentityRegistryContract {
fn linked_tokens(e: &Env) -> Vec<Address> {
binder::linked_tokens(e)
}

#[only_role(operator, "manager")]
fn bind_token(e: &Env, token: Address, operator: Address) {
binder::bind_token(e, &token);
}

#[only_role(operator, "manager")]
fn unbind_token(e: &Env, token: Address, operator: Address) {
binder::unbind_token(e, &token);
}
}

#[contractimpl]
impl IdentityRegistryStorage for IdentityRegistryContract {
#[only_role(operator, "manager")]
fn add_identity(
e: &Env,
account: Address,
identity: Address,
initial_profiles: Vec<Val>,
operator: Address,
) {
let country_data = Vec::from_iter(
e,
initial_profiles.iter().map(|profile| CountryData::from_val(e, &profile)),
);
identity_storage::add_identity(
e,
&account,
&identity,
IdentityType::Individual,
&country_data,
);
}

#[only_role(operator, "manager")]
fn modify_identity(e: &Env, account: Address, new_identity: Address, operator: Address) {
identity_storage::modify_identity(e, &account, &new_identity);
}

#[only_role(operator, "manager")]
fn remove_identity(e: &Env, account: Address, operator: Address) {
identity_storage::remove_identity(e, &account);
}

fn stored_identity(e: &Env, account: Address) -> Address {
identity_storage::stored_identity(e, &account)
}

#[only_role(operator, "manager")]
fn recover_identity(e: &Env, old_account: Address, new_account: Address, operator: Address) {
identity_storage::recover_identity(e, &old_account, &new_account);
}

fn get_recovered_to(e: &Env, old: Address) -> Option<Address> {
identity_storage::get_recovered_to(e, &old)
}
}

#[contractimpl]
impl CountryDataManager for IdentityRegistryContract {
#[only_role(operator, "manager")]
fn add_country_data_entries(e: &Env, account: Address, profiles: Vec<Val>, operator: Address) {
let country_data =
Vec::from_iter(e, profiles.iter().map(|profile| CountryData::from_val(e, &profile)));
identity_storage::add_country_data_entries(e, &account, &country_data);
}

#[only_role(operator, "manager")]
fn modify_country_data(e: &Env, account: Address, index: u32, profile: Val, operator: Address) {
let country_data = CountryData::from_val(e, &profile);
identity_storage::modify_country_data(e, &account, index, &country_data);
}

#[only_role(operator, "manager")]
fn delete_country_data(e: &Env, account: Address, index: u32, operator: Address) {
identity_storage::delete_country_data(e, &account, index);
}

fn get_country_data(e: &Env, account: Address, index: u32) -> Val {
identity_storage::get_country_data(e, &account, index).into_val(e)
}

fn get_country_data_entries(e: &Env, account: Address) -> Vec<Val> {
Vec::from_iter(
e,
identity_storage::get_country_data_entries(e, &account)
.iter()
.map(|profile| profile.into_val(e)),
)
}
}
Loading
Loading