-
Notifications
You must be signed in to change notification settings - Fork 54
RWA: balance and supply compliance modules #651
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
8
commits into
OpenZeppelin:main
Choose a base branch
from
pasevin:feat/rwa-balance-supply-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 all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
db21540
feat(rwa): add standalone balance compliance modules
pasevin 450e24b
Merge branch 'main' into feat/rwa-balance-supply-standalone
pasevin 069503d
chore: sync Cargo.lock with workspace manifests
pasevin bb0ad21
refactor: apply storage-first pattern to max_balance and supply_limit…
pasevin 04bb99c
Merge remote-tracking branch 'upstream/main' into feat/rwa-balance-su…
pasevin cebd108
chore: sync Cargo.lock after merging upstream/main v0.7.1
pasevin 86d46f1
refactor: align standalone balance and supply examples
pasevin a09f383
test: cover balance and supply storage branches
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-max-balance" | ||
| 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,125 @@ | ||
| use soroban_sdk::{contract, contractimpl, contracttype, Address, Env, String, Vec}; | ||
| use stellar_tokens::rwa::compliance::{ | ||
| modules::{ | ||
| max_balance::storage as max_balance, | ||
| storage::{ | ||
| get_compliance_address, module_name, set_compliance_address, set_irs_address, | ||
| ComplianceModuleStorageKey, | ||
| }, | ||
| ComplianceModule, | ||
| }, | ||
| ComplianceHook, | ||
| }; | ||
|
|
||
| #[contracttype] | ||
| enum DataKey { | ||
| Admin, | ||
| } | ||
|
|
||
| #[contract] | ||
| pub struct MaxBalanceContract; | ||
|
|
||
| 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 MaxBalanceContract { | ||
| 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 set_max_balance(e: &Env, token: Address, max: i128) { | ||
| require_module_admin_or_compliance_auth(e); | ||
| max_balance::configure_max_balance(e, &token, max); | ||
| } | ||
|
|
||
| pub fn pre_set_identity_balance(e: &Env, token: Address, identity: Address, balance: i128) { | ||
| require_module_admin_or_compliance_auth(e); | ||
| max_balance::pre_set_identity_balance(e, &token, &identity, balance); | ||
| } | ||
|
|
||
| pub fn batch_pre_set_identity_balances( | ||
| e: &Env, | ||
| token: Address, | ||
| identities: Vec<Address>, | ||
| balances: Vec<i128>, | ||
| ) { | ||
| require_module_admin_or_compliance_auth(e); | ||
| max_balance::batch_pre_set_identity_balances(e, &token, &identities, &balances); | ||
| } | ||
|
|
||
| pub fn get_max_balance(e: &Env, token: Address) -> i128 { | ||
| max_balance::get_max_balance(e, &token) | ||
| } | ||
|
|
||
| pub fn get_investor_balance(e: &Env, token: Address, identity: Address) -> i128 { | ||
| max_balance::get_id_balance(e, &token, &identity) | ||
| } | ||
|
|
||
| pub fn required_hooks(e: &Env) -> Vec<ComplianceHook> { | ||
| max_balance::required_hooks(e) | ||
| } | ||
|
|
||
| pub fn verify_hook_wiring(e: &Env) { | ||
| max_balance::verify_hook_wiring(e); | ||
| } | ||
| } | ||
|
|
||
| #[contractimpl(contracttrait)] | ||
| impl ComplianceModule for MaxBalanceContract { | ||
| fn on_transfer(e: &Env, from: Address, to: Address, amount: i128, token: Address) { | ||
| require_module_admin_or_compliance_auth(e); | ||
| max_balance::on_transfer(e, &from, &to, amount, &token); | ||
| } | ||
|
|
||
| fn on_created(e: &Env, to: Address, amount: i128, token: Address) { | ||
| require_module_admin_or_compliance_auth(e); | ||
| max_balance::on_created(e, &to, amount, &token); | ||
| } | ||
|
|
||
| fn on_destroyed(e: &Env, from: Address, amount: i128, token: Address) { | ||
| require_module_admin_or_compliance_auth(e); | ||
| max_balance::on_destroyed(e, &from, amount, &token); | ||
| } | ||
|
|
||
| fn can_transfer(e: &Env, from: Address, to: Address, amount: i128, token: Address) -> bool { | ||
| max_balance::can_transfer(e, &from, &to, amount, &token) | ||
| } | ||
|
|
||
| fn can_create(e: &Env, to: Address, amount: i128, token: Address) -> bool { | ||
| max_balance::can_create(e, &to, amount, &token) | ||
| } | ||
|
|
||
| fn name(e: &Env) -> String { | ||
| module_name(e, "MaxBalanceModule") | ||
| } | ||
|
|
||
| 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't think of cases in which authorization for setters comes from compliance 🤔 Here, we might assume the authorization is from admin, while in hooks it's from the compliance contract. As a ref, the T-REX implementation checks compliance's owner in setters.