Skip to content

Commit

Permalink
Docs: Update Gitbook (#35)
Browse files Browse the repository at this point in the history
* GITBOOK-16: No subject

* GITBOOK-17: No subject

* GITBOOK-19: No subject
  • Loading branch information
fazzatti authored Dec 13, 2023
1 parent ca8d462 commit 21de395
Show file tree
Hide file tree
Showing 13 changed files with 786 additions and 20 deletions.
Binary file not shown.
2 changes: 2 additions & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

* [Issuing your first asset](tutorials/issuing-your-first-asset.md)
* [Bulk Payments](tutorials/bulk-payments.md)
* [E2E Certificate of Deposit demo](tutorials/e2e-certificate-of-deposit-demo.md)

## 📄 Reference

Expand All @@ -18,6 +19,7 @@
* [Friendbot](reference/account/helpers/friendbot.md)
* [Asset](reference/asset/README.md)
* [Classic Asset Handler](reference/asset/classic-asset-handler.md)
* [Stellar Asset Contract Handler](reference/asset/stellar-asset-contract-handler.md)
* [Constants](reference/constants.md)
* [Contracts](reference/contracts/README.md)
* [Contract Engine](reference/contracts/contract-engine.md)
Expand Down
3 changes: 3 additions & 0 deletions docs/reference/asset/stellar-asset-contract-handler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Stellar Asset Contract Handler

Coming Soon
106 changes: 106 additions & 0 deletions docs/reference/contracts/certificate-of-deposit-client.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,108 @@
# Certificate of Deposit Client

The `CertificateOfDepositClient` class extends `ContractEngine` to interact with a specific smart contract implementation for a Certificate of Deposit on the Stellar network. It implements methods for managing deposits, withdrawals, and fetching contract-related data.

{% hint style="info" %}
Refer to the [e2e-certificate-of-deposit-demo.md](../../tutorials/e2e-certificate-of-deposit-demo.md "mention") for a detailed use case and code example including this client. A fully integrated version of this contract implementation with UI can also be seen at the [Custodial Asset Sandbox](https://stellar.cheesecakelabs.com/).
{% endhint %}

## **Constructor**

* **Parameters**:
* `contractId`: Contract ID of the deployed contract.
* `network`: Network configuration.
* `rpcHandler`: RPC handler for interactions.
* **Purpose**: Initializes the client with the necessary configurations to interact with the Certificate of Deposit contract.

## **Methods**

### deposit

* **Purpose**: Deposits assets into the contract.
* **Parameters**:
* `address`: Account address making the deposit.
* `amount`: Deposit amount.
* `signers`: Authorizing signers.
* `header`: Transaction header.
* `feeBump`: Optional fee bump.

### withdraw

* **Purpose**: Withdraws assets from the contract.
* **Parameters**:
* `address`: Account address withdrawing assets.
* `acceptPrematureWithdraw`: Flag for premature withdrawal acceptance.
* `signers`: Authorizing signers.
* `header`: Transaction header.
* `feeBump`: Optional fee bump.

### getEstimatedYield

* **Purpose**: Fetches estimated yield.
* **Parameters**:
* `address`: Account address.
* `header`: Transaction header.

### getPosition

* **Purpose**: Retrieves current position.
* **Parameters**:
* `address`: Account address.
* `header`: Transaction header.

### getEstimatedPrematureWithdraw

* **Purpose**: Estimates premature withdrawal amount.
* **Parameters**:
* `address`: Account address.
* `header`: Transaction header.

### getTimeLeft

* **Purpose**: Determines time left for penalty-free withdrawal.
* **Parameters**:
* `address`: Account address.
* `header`: Transaction header.

### initialize

* **Purpose**: Initializes contract state.
* **Parameters**:
* `admin`, `asset`, `term`, `compoundStep`, `yieldRate`, `minDeposit`, `penaltyRate`, `allowancePeriod`: Contract parameters.
* `signers`: Authorizing signers.
* `header`: Transaction header.
* `feeBump`: Optional fee bump.

{% hint style="info" %}
The initialization parameters affect the CD rules as the following:



* **Admin**\
Defines which account can manage the CD contract and also receives and provides the funds from/to the users.
* **Asset** \
The contract id of the Stellar Asset Contract for the wrapped Classic Asset this CD interacts with.
* **Term** (seconds)\
For how long this CD will accrue interest to a open deposit position.
* **Compound Step** (seconds)\
How often will the interest be paid/compound. If set to '0', a different yield rate calculation is used and the interest rate will be applied linearly until the end of the term.
* **Yield Rate** (1 unit = 0.01%)\
How much interest will be paid out. For compounding interest, this means at every compound interval, while the linear rate will reach this rate at the end of the term.
* **Minimum Deposit**\
Minimum amount accepted for a deposit.
* **Penalty Rate** (1 unit = 0.01%)\
If a user accepts the early withdraw, before the term is finished, this penalty rate will be applied to the earned interest. \
\
E.g. _A 200 units position (100 deposit + 100 earned yield) withdrawing early with a penalty rate of 50% will receive 150 units(100 deposit + 50 earned yield)_ 

$$
Withdrawn Amount=Deposit+(Yield−Penalty Rate×Yield)
$$

* **Allowance Period** (Expiration ledger number)\
Until which ledger will the allowance for the contract to access the admin funds be valid.
{% endhint %}



This class provides a structured and convenient way to interact with the Certificate of Deposit contract on the Stellar network, encapsulating complex contract interactions into simpler method calls.
51 changes: 46 additions & 5 deletions docs/reference/contracts/contract-engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@ The `ContractEngine` class serves as a base for building clients that interact w

* **Parameters**:
* `network`: The network configuration for the Stellar blockchain.
* `rpcHandler`: The RPC handler for interacting with the Stellar network. When not provided, will connect directly to the RPC url set in the network configuration.
* `spec`: A `ContractSpec` object detailing the contract's specifications.
* `contractId`: A string representing the unique identifier of the deployed contract.

## Methods
* `rpcHandler`: Optional. Interacts with the Stellar network; defaults to RPC URL in network config.
* `spec`: ContractSpec detailing contract specifications.
* `contractId`: Optional. Unique identifier of the deployed contract.
* `wasm`: Optional. Buffer of the loaded wasm file with compiled contract code.
* `wasmHash`: Optional. Hash of the deployed wasm code.

{% hint style="info" %}
You can initialize a contract engine or child client contract in different ways. Since the contract id, wasm and wasm hash are all optional, choose whichever initialization is best for your use case.\
\
When executing the methods, a validation will take place to throw an error in case a requirement is not met.\
\
E.g. Attempting to deploy a contract instance without having a wasmHash. It would've been necessary to either initiate the instance with this argument or, to have performed a <mark style="color:blue;">`uploadWasm`</mark> so that the wasm hash would've been updated in the instance.
{% endhint %}

## Core Methods

### readFromContract

Expand All @@ -31,6 +41,37 @@ The `ContractEngine` class serves as a base for building clients that interact w
* `feeBump`: Optional `FeeBumpHeader` for fee bumping.
* **Returns**: The output of the contract invocation after the transaction is processed.



## **Meta Management Methods**

These methods in the ContractEngine facilitate the necessary steps for contract preparation and deployment, ensuring efficient and accurate interaction with the Soroban network.

#### **uploadWasm**

* **Purpose**: To upload the contract wasm to the network and update the wasm hash in the contract engine.
* **Parameters**:
* `wasm`: The wasm file buffer.
* `header`: The header for the transaction.
* `signers`: The signers for the transaction.
* `feeBump`: Optional fee bump header.
* **Returns**: No direct return. Updates wasm hash in the engine.
* **Usage**: Used for uploading wasm files to the Soroban server, necessary for contract deployment.

#### **deploy**

* **Purpose**: Deploys a new contract instance to the network and updates the contract ID in the engine.
* **Parameters**:
* `wasmHash`: The wasm hash of the contract to be deployed.
* `header`: The header for the transaction.
* `signers`: The signers for the transaction.
* `feeBump`: Optional fee bump header.
* **Returns**: No direct return. Updates contract ID in the engine.
* **Usage**: Critical for deploying contracts to the Soroban network, enabling interactions with the contract instance.

\


## Example Usage

The `CertificateOfDepositClient` class (See [certificate-of-deposit-client.md](certificate-of-deposit-client.md "mention")) is an example of how to extend the `ContractEngine` class to interact with a specific smart contract. This client showcases the implementation of methods that utilize both `readFromContract` and `invokeContract` functionalities provided by `ContractEngine`.
Expand Down
97 changes: 97 additions & 0 deletions docs/reference/core/channel-accounts-transaction-submitter.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,99 @@
# Channel Accounts Transaction Submitter

### ChannelAccountsTransactionSubmitter Class Overview

The `ChannelAccountsTransactionSubmitter` class, implementing the `TransactionSubmitter` interface, is specifically designed for submitting transactions using a pool of channel accounts. This class is vital in scenarios where high transaction throughput is required on the Stellar network. It manages multiple channel accounts to parallelize transaction submissions, optimizing network interactions and reducing potential sequence errors. \
\
For more in-depth information refer to Stellar's official documentation on [Channel Accounts](https://developers.stellar.org/docs/encyclopedia/channel-accounts).



{% hint style="info" %}
See the [bulk-payments.md](../../tutorials/bulk-payments.md "mention") tutorial on how this class can be utilized to perform several payments in parallel
{% endhint %}

### Core Functionalities

* #### Constructor

* **Parameters**:
* `network`: Configuration for the Stellar network.
* `feeBump` (optional): Details for fee bumping transactions.\


#### registerChannels

* **Purpose**: Adds channel accounts to the pool for transaction processing.
* **Parameters**: `channels` (Array of `DefaultAccountHandler`).\


#### createEnvelope

* **Purpose**: Creates a transaction envelope using a channel account.
* **Parameters**: `txInvocation` (TransactionInvocation).
* **Returns**: Object containing `TransactionBuilder` and updated transaction invocation.\


#### submit

* **Purpose**: Submits a transaction to the Stellar network.
* **Parameters**: `envelope` (Transaction or FeeBumpTransaction).
* **Returns**: Response from the Horizon server.\


#### postProcessTransaction

* **Purpose**: Handles the response after transaction submission.
* **Parameters**: `response` (HorizonNamespace.SubmitTransactionResponse).
* **Returns**: Processed transaction data or error on failure.\


#### noChannelPipeline

* **Purpose**: Provides a fallback mechanism when no free channel is available.
* **Returns**: Allocated `DefaultAccountHandler` after a waiting period.\


#### getChannels

* **Purpose**: Retrieves the list of registered channel accounts.
* **Returns**: Array of `DefaultAccountHandler`.\


The `ChannelAccountsTransactionSubmitter` plays a critical role in the transaction processing pipeline, especially when handling high volumes of transactions. It ensures efficient transaction submission by utilizing channel accounts, and it manages the allocation and release of these accounts to optimize network throughput.

### How to use

1. **Create TransactionSubmitter Instance**: Instantiate the `ChannelAccountsTransactionSubmitter` with the Stellar network configuration and optional fee bump settings.

{% code overflow="wrap" %}
```typescript
const transactionSubmitter = new
StellarPlus.Core.Classic.ChannelAccountsTransactionSubmitter(network,
defaultFeeBump);
```
{% endcode %}
2. **Register Channel Accounts**: Initialize and register channel accounts for transaction processing. This step is crucial for handling high-frequency transactions.

{% code overflow="wrap" %}
```typescript
await transactionSubmitter.registerChannels(
await StellarPlus.Utils.ChannelAccountsHandler.openChannels({
/* ... */ })
);
```
{% endcode %}
3. **Use the Submitter:** Provide the submitter to a Soroban class that extends the [soroban-transaction-processor.md](soroban-transaction-processor.md "mention") and accepts a Submitter instance. All transactions processed by this instance will make use of the channel accounts.

{% code overflow="wrap" %}
```typescript
const cakeToken = new StellarPlus.Asset.ClassicAssetHandler(
"CAKE",
issuerAccount.getPublicKey(),
network,
issuerAccount,
transactionSubmitter
);
```
{% endcode %}
Loading

0 comments on commit 21de395

Please sign in to comment.