Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
tweaks to examples and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch committed Feb 20, 2024
1 parent 847db42 commit 18d6449
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 48 deletions.
36 changes: 4 additions & 32 deletions docs/guides/cli/deploy-stellar-asset-contract.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,37 +47,9 @@ soroban contract id asset \
--asset native
```

The contract address can then be used in a Soroban contract as any contract.
The Soroban SDK provides `soroban_sdk::token` an interface to the Stellar Asset
Contract. There are two different clients:

- `token::Client` gives access to the token operations part of the SEP-41 token
interface, such as `transfer` or `burn`.
- `token::StellarAssetInterface` gives access to the token operations specific
to Stellar Asset Contracts, such as `mint`.

```rust
use soroban_sdk::token;

struct MyContract;

#[contractimpl]
impl MyContract {
fn token_fn(e: Env, token: Address) {
// Create a client instance for the provided token identifier. If the
// `token_id` value corresponds to an SAC contract, then SAC implementation
// is used.
let client = token::Client::new(&env, &token);
// Call token operations part of the SEP-41 token interface
client.burn(...);

let sac_client = token::StellarAssetInterface::new(&env, &token);
// Call token operations which are not part of the SEP-41 token interface
// but part of the CAP-46-6 Smart Contract Standardized Asset
sac_client.mint(...);
}
}
```

[Stellar Asset Contract]: ../../tokens/stellar-asset-contract.mdx
[Lumens]: https://developers.stellar.org/docs/fundamentals-and-concepts/lumens
[SEP-41]: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0041.md
[`soroban_sdk::token`]: https://docs.rs/soroban-sdk/latest/soroban_sdk/token/
[`token::TokenClient`]: https://docs.rs/soroban-sdk/latest/soroban_sdk/token/struct.TokenClient.html
[`token::StellarAssetClient`]: https://docs.rs/soroban-sdk/latest/soroban_sdk/token/struct.StellarAssetClient.html
30 changes: 16 additions & 14 deletions docs/tokens/stellar-asset-contract.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -156,30 +156,29 @@ struct MyContract;

#[contractimpl]
impl MyContract {
fn token_fn(e: Env, token_id: BytesN<32>) {
// Create a client instance for the provided token identifier. If the
// `token_id` value corresponds to an SAC contract, then SAC implementation
// is used.
let client = token::Client::new(&env, &token_id);
fn token_fn(e: Env, id: Address) {
// Create a client instance for the provided token identifier. If the id
// value corresponds to an SAC contract, then SAC implementation is used.
let client = token::Client::new(&env, &id);
// Call token operations part of the SEP-41 token interface
client.transfer(...);
}
}
```

:::info Different clients
:::info Clients

A client created by `token::Client` exclusively implements the functions
defined by the SEP-41 [Token Interface]. But the Stellar
Asset Contract exposes additional functions such as `mint`. To access these
functions, another client needs to be used: `token::StellarAssetInterface`.
This client only implements the functions which are not part of the SEP-41.
A client created by [`token::Client`] implements the functions defined by any
contract that implements the SEP-41 [Token Interface]. But the Stellar Asset
Contract exposes additional functions such as `mint`. To access the additional
functions, another client needs to be used: [`token::StellarAssetClient`]. This
client only implements the functions which are not part of the SEP-41.

```rust
let sac_client = token::StellarAssetInterface::new(&env, &token_id);
let client = token::StellarAssetClient::new(&env, &id);
// Call token operations which are not part of the SEP-41 token interface
// but part of the CAP-46-6 Smart Contract Standardized Asset
sac_client.mint(...);
client.mint(...);
```

:::
Expand All @@ -204,7 +203,7 @@ tokens using `register_stellar_asset_contract`. For example:
```rust
let admin = Address::random();
let user = Address::random();
let token = token::StellarAssetInterface::new(e, &e.register_stellar_asset_contract(admin.clone()));
let token = StellarAssetClient::new(e, &e.register_stellar_asset_contract(admin.clone()));
token.mint(&admin, &user, &1000);
```

Expand All @@ -218,3 +217,6 @@ This interface can be found in the [SDK]. It extends the common

[SDK]: https://github.com/stellar/rs-soroban-sdk/blob/v20.0.0/soroban-sdk/src/token.rs
[Token Interface]: token-interface.mdx
[`soroban_sdk::token`]: https://docs.rs/soroban-sdk/latest/soroban_sdk/token/
[`token::TokenClient`]: https://docs.rs/soroban-sdk/latest/soroban_sdk/token/struct.TokenClient.html
[`token::StellarAssetClient`]: https://docs.rs/soroban-sdk/latest/soroban_sdk/token/struct.StellarAssetClient.html
5 changes: 3 additions & 2 deletions docs/tutorials/tokens.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,8 @@ transfers, balance queries, etc.). In an effort to minimize repetition and
streamline token deployments, Soroban implements the [Token Interface], which
provides a uniform, predictable interface for developers and users.

Creating a Soroban token compatible contract from an existing Stellar asset is very easy,
it requires deploying the built-in [Stellar Asset Contract].
Creating a Soroban token compatible contract from an existing Stellar asset is
very easy, it requires deploying the built-in [Stellar Asset Contract].

This example contract, however, demonstrates how a smart contract token might be
constructed that doesn't take advantage of the Stellar Asset Contract, but does
Expand Down Expand Up @@ -648,6 +648,7 @@ _require_ the right kind of behavior to take place.

:::


## Tests

Open the `token/src/test.rs` file to follow along.
Expand Down

0 comments on commit 18d6449

Please sign in to comment.