Skip to content

Commit 9f9b1bc

Browse files
committed
chore: added changes to index page, ownable, and fungible
1 parent adc3dfa commit 9f9b1bc

3 files changed

Lines changed: 66 additions & 3 deletions

File tree

content/stellar-contracts/access/ownable.mdx

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,51 @@ Until the transfer is accepted, the original owner retains full control and can
2525

2626
The Ownable module allows the owner to permanently renounce ownership of the contract. This is a one-way operation that cannot be undone. After ownership is renounced, all functions marked with `#[only_owner]` become permanently inaccessible.
2727

28-
This feature is useful for contracts that need to become fully decentralized after an initial setup phase.
28+
This feature is useful for contracts that need to become fully decentralized after an initial setup phase, or to make a contract **immutable and non-upgradeable** by removing administrative control entirely.
29+
30+
#### Example: Making a Contract Immutable
31+
32+
A common use case is renouncing ownership after initial setup to ensure the contract becomes immutable and cannot be upgraded:
33+
34+
```rust
35+
use soroban_sdk::{contract, contractimpl, Address, Env};
36+
use stellar_access::ownable::{self as ownable, Ownable};
37+
use stellar_macros::only_owner;
38+
39+
#[contract]
40+
pub struct MyContract;
41+
42+
#[contractimpl]
43+
impl MyContract {
44+
pub fn __constructor(e: &Env, initial_owner: Address) {
45+
ownable::set_owner(e, &initial_owner);
46+
}
47+
48+
#[only_owner]
49+
pub fn finalize_and_lock(e: &Env) {
50+
// Perform any final configuration here
51+
// ...
52+
53+
// Renounce ownership to make the contract immutable
54+
// After this call, no owner-restricted functions can ever be called again
55+
ownable::renounce_ownership(e);
56+
57+
// The contract is now permanently locked and non-upgradeable
58+
}
59+
60+
#[only_owner]
61+
pub fn emergency_upgrade(e: &Env, new_wasm_hash: BytesN<32>) {
62+
// This function becomes permanently inaccessible after renounce_ownership
63+
e.deployer().update_current_contract_wasm(new_wasm_hash);
64+
}
65+
}
66+
```
67+
68+
**Important Notes:**
69+
- Once `renounce_ownership()` is called, there is no way to restore ownership
70+
- All functions marked with `#[only_owner]` become permanently inaccessible
71+
- This effectively makes the contract immutable and non-upgradeable
72+
- You cannot renounce ownership while a transfer is in progress
2973

3074
### Procedural Macro
3175

content/stellar-contracts/index.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Explore our comprehensive suite of secure and scalable smart contract utilities
88

99
* **[Fungible Tokens](/stellar-contracts/tokens/fungible/fungible)**: Digital assets representing a fixed or dynamic supply of identical units.
1010
* **[Non-Fungible Tokens (NFTs)](/stellar-contracts/tokens/non-fungible/non-fungible)**: Unique digital assets with verifiable ownership.
11-
* **Multi-Tokens**: Hybrid tokens enabling both fungible and non-fungible token functionalities (work in progress).
1211

1312
## Access Control
1413

@@ -31,7 +30,6 @@ we use the following convention:
3130

3231
* Fungible: `1XX`
3332
* Non-Fungible: `2XX`
34-
* Multi-Token: `3XX`
3533

3634
Any future tokens will continue from `4XX`, `5XX`, and so on.
3735

content/stellar-contracts/tokens/fungible/fungible.mdx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,25 @@ The module provides several implementation options to suit different use cases:
2222

2323
These implementations share core functionality and a common interface, exposing identical contract functions as entry-points. However, the extensions provide specialized behavior by overriding certain functions to implement their specific requirements.
2424

25+
## SAC
26+
27+
The Stellar Asset Contract (SAC) is a special built-in implementation of [CAP-46-6 Smart Contract Standardized Asset](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0046-06.md) and [SEP-41 Token Interface](https://developers.stellar.org/docs/tokens/token-interface). The SAC acts as a bridge between traditional Stellar assets and Soroban smart contracts.
28+
29+
SAC is NOT a library or custom contract; it's a built-in protocol feature that automatically wraps existing Stellar assets (like USDC, XLM, or any issued asset) so they can be used in smart contracts. Think of it as the "smart contract version" of any Stellar asset.
30+
31+
Key points to know:
32+
- Every Stellar asset gets its own SAC instance with a deterministic contract address
33+
- No bridging or wrapping tokens needed - it's the same asset, just accessible via smart contracts
34+
- Anyone can deploy a SAC for any asset (the original issuer doesn't need to be involved)
35+
- SAC implements the same SEP-41 interface as OpenZeppelin fungible tokens, ensuring compatibility
36+
- When you transfer between Stellar accounts and contracts, the balances are stored differently but represent the same underlying asset
37+
38+
When to use SAC vs OpenZeppelin tokens:
39+
- Use SAC: When you want to interact with existing Stellar assets (USDC, XLM, etc.) in your smart contracts
40+
- Use OpenZeppelin: When creating new custom tokens with specialized logic, access controls, or unique tokenomics
41+
42+
For example, if you want to build a DeFi protocol that uses USDC, you'd deploy the SAC for USDC rather than creating a new token. Users can then interact with the same USDC they hold in their Stellar wallets directly through your smart contract.
43+
2544
## Usage
2645

2746
We’ll create a simple token for a game’s in-game currency. Players can earn tokens by completing tasks,
@@ -135,3 +154,5 @@ To comply with the SEP-41 specification, a contract must implement both the `Fun
135154
The library handles the TTL (Time-To-Live) of only `temporary` and `persistent` storage entries declared
136155
by the library. The `instance` TTL management is left to the implementor due to flexibility. The library
137156
exposes default values for extending the TTL: `INSTANCE_TTL_THRESHOLD` and `INSTANCE_EXTEND_AMOUNT`.
157+
158+
For a comprehensive understanding of Soroban's three storage types (`temporary`, `persistent`, and `instance`) and their archival behavior, see the [State Archival documentation](https://developers.stellar.org/docs/learn/fundamentals/contract-development/storage/state-archival#contract-data-type-descriptions).

0 commit comments

Comments
 (0)