-
Notifications
You must be signed in to change notification settings - Fork 54
RWA: country compliance modules #650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pasevin
wants to merge
24
commits into
OpenZeppelin:main
Choose a base branch
from
pasevin:feat/rwa-country-standalone
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
30c56ef
feat(rwa): add standalone country compliance modules
pasevin da529e5
refactor(rwa): move country module tests into sibling files
pasevin a6babd6
Merge branch 'main' into feat/rwa-country-standalone
pasevin 27b08c3
chore: sync Cargo.lock with workspace manifests
pasevin 301019a
refactor: apply storage-first pattern to country modules
pasevin ff8dadd
Merge remote-tracking branch 'upstream/main' into feat/rwa-country-st…
pasevin afa1dd8
chore: sync Cargo.lock after merging upstream/main v0.7.1
pasevin 506a03f
refactor: finish country module alignment
pasevin 2188957
refactor: align country modules with native traits
pasevin b91cd5b
refactor: tidy country membership storage
pasevin bd01f0b
chore: refresh ethnum lockfile entry
pasevin 43764a1
Merge branch 'main' into feat/rwa-country-standalone
pasevin b44ecf8
refactor: add country allow event helpers
pasevin abca49c
refactor: wire country event helpers
pasevin f4b49bd
style: align country storage docs
pasevin 5da6138
refactor: compose country module traits
pasevin 8865101
style: order country module items
pasevin 4d9ad42
refactor: use access control admin helpers
pasevin 716a8a6
style: use full country module paths
pasevin 5394955
docs: polish country trait docs
pasevin a06052b
docs: shorten country storage error links
pasevin 55da13e
docs: fix country error link targets
pasevin 3d061fd
chore: refresh country example lockfile
pasevin 5b05459
Merge branch 'main' into feat/rwa-country-standalone
pasevin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
|
pasevin marked this conversation as resolved.
Outdated
|
||
|
|
||
| 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); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #![no_std] | ||
|
|
||
| pub mod contract; | ||
| #[cfg(test)] | ||
| mod test; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.