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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ lcov.info
coverage/

**/test_snapshots/

# Compiled WASM artifacts and testnet state
examples/rwa-deploy/wasm/
examples/rwa-deploy/testnet-addresses.json
93 changes: 90 additions & 3 deletions Cargo.lock

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

18 changes: 17 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,23 @@ 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-deploy/irs",
"examples/rwa-deploy/verifier",
"examples/rwa-deploy/compliance",
"examples/rwa-deploy/token",
"examples/sac-admin-generic",
"examples/sac-admin-wrapper",
"examples/multisig-smart-account/*",
Expand Down
22 changes: 22 additions & 0 deletions examples/rwa-country-allow/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "rwa-country-allow"
edition.workspace = true
license.workspace = true
repository.workspace = true
publish = false
version.workspace = true
authors.workspace = true

[package.metadata.stellar]
cargo_inherit = true

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

[dependencies]
soroban-sdk = { workspace = true }
stellar-tokens = { workspace = true }

[dev-dependencies]
soroban-sdk = { workspace = true, features = ["testutils"] }
101 changes: 101 additions & 0 deletions examples/rwa-country-allow/src/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
use soroban_sdk::{contract, contractimpl, contracttype, Address, Env, String, Vec};
use stellar_tokens::rwa::compliance::modules::{
country_allow::storage as country_allow,
storage::{
get_compliance_address, module_name, set_compliance_address, set_irs_address,
ComplianceModuleStorageKey,
},
ComplianceModule,
};

#[contracttype]
enum DataKey {
Admin,
}

#[contract]
pub struct CountryAllowContract;

fn set_admin(e: &Env, admin: &Address) {
e.storage().instance().set(&DataKey::Admin, admin);
}

fn get_admin(e: &Env) -> Address {
e.storage().instance().get(&DataKey::Admin).expect("admin must be set")
}

fn require_module_admin_or_compliance_auth(e: &Env) {
if let Some(compliance) =
e.storage().instance().get::<_, Address>(&ComplianceModuleStorageKey::Compliance)
{
compliance.require_auth();
} else {
get_admin(e).require_auth();
}
}

#[contractimpl]
impl CountryAllowContract {
pub fn __constructor(e: &Env, admin: Address) {
set_admin(e, &admin);
}

pub fn set_identity_registry_storage(e: &Env, token: Address, irs: Address) {
require_module_admin_or_compliance_auth(e);
set_irs_address(e, &token, &irs);
}

pub fn add_allowed_country(e: &Env, token: Address, country: u32) {
require_module_admin_or_compliance_auth(e);
country_allow::add_allowed_country(e, &token, country);
}

pub fn remove_allowed_country(e: &Env, token: Address, country: u32) {
require_module_admin_or_compliance_auth(e);
country_allow::remove_allowed_country(e, &token, country);
}

pub fn batch_allow_countries(e: &Env, token: Address, countries: Vec<u32>) {
require_module_admin_or_compliance_auth(e);
country_allow::batch_allow_countries(e, &token, &countries);
}

pub fn batch_disallow_countries(e: &Env, token: Address, countries: Vec<u32>) {
require_module_admin_or_compliance_auth(e);
country_allow::batch_disallow_countries(e, &token, &countries);
}

pub fn is_country_allowed(e: &Env, token: Address, country: u32) -> bool {
country_allow::is_country_allowed(e, &token, country)
}
}

#[contractimpl(contracttrait)]
impl ComplianceModule for CountryAllowContract {
fn on_transfer(_e: &Env, _from: Address, _to: Address, _amount: i128, _token: Address) {}

fn on_created(_e: &Env, _to: Address, _amount: i128, _token: Address) {}

fn on_destroyed(_e: &Env, _from: Address, _amount: i128, _token: Address) {}

fn can_transfer(e: &Env, _from: Address, to: Address, _amount: i128, token: Address) -> bool {
country_allow::can_transfer(e, &to, &token)
}

fn can_create(e: &Env, to: Address, _amount: i128, token: Address) -> bool {
country_allow::can_transfer(e, &to, &token)
}

fn name(e: &Env) -> String {
module_name(e, "CountryAllowModule")
}

fn get_compliance_address(e: &Env) -> Address {
get_compliance_address(e)
}

fn set_compliance_address(e: &Env, compliance: Address) {
get_admin(e).require_auth();
set_compliance_address(e, &compliance);
}
}
5 changes: 5 additions & 0 deletions examples/rwa-country-allow/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![no_std]

pub mod contract;
#[cfg(test)]
mod test;
Loading
Loading