Skip to content

Commit

Permalink
Merge pull request #3 from zarbanio/chore/vault-example
Browse files Browse the repository at this point in the history
chore(example): add readme, docs and create vault example
  • Loading branch information
arashalaei authored Dec 23, 2024
2 parents b386f06 + 2e57003 commit 8d2fc1c
Show file tree
Hide file tree
Showing 227 changed files with 10,118 additions and 149 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go-ethereum
75 changes: 75 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Contributing to Zarban SDK

We appreciate your interest in contributing to the Zarban SDK! Contributions are key to improving our project, and we welcome bug reports, feature requests, and pull requests.

## How to Contribute

### 1. Fork the Repository

- Start by [forking the repository](https://github.com/zarbanio/zarban-go/fork).

### 2. Clone Your Fork

```bash
git clone https://github.com/your-username/zarban-go.git
cd zarban-go
```

### 3. Create a New Branch

Use a descriptive branch name, e.g., `feature/feature-name` or `fix/issue-description`.

```bash
git checkout -b feature/your-feature
```

### 4. Make Your Changes

Ensure that your code is well-documented.
Follow the project's code style and structure.

### 5. Run Tests

Run the tests to make sure everything works as expected.

### 6. Commit Your Changes

Add a meaningful commit message. Refer to issues by their number if applicable (e.g., #123).

```bash
git commit -m "Add feature: detailed feature description"
```

### 7. Push Your Changes

```bash
git push origin feature/your-feature
```

### 8. Open a Pull Request

- Go to the original repository on GitHub.
- Click on **New Pull Request**.
- Select the branch you just pushed from the dropdown menu.
- Add a descriptive title and summary of your changes.
- Reference any relevant issues (e.g., `#123`).

markdown

## Reporting Bugs

If you encounter a bug, please help us improve the Zarban SDK by reporting it.

- **Search Existing Issues**: Before submitting, check the [GitHub Issues](https://github.com/zarbanio/zarban-go/issues) to see if the problem has already been reported.
- **Open a New Issue**: If the issue is not reported, open a new issue and provide the following details:
- A clear description of the bug.
- Steps to reproduce the issue.
- Expected and actual behavior.
- Relevant error messages or screenshots, if applicable.
- Version of Zarban SDK you are using.

## Code Style

Please ensure your code adheres to PEP 8 and includes type hints where possible.

Thank you for your contribution!
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) [2024] Zarban

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
241 changes: 240 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,240 @@
# zarban-go
# Zarban SDK

<p align="center">
<img src="https://zarban.io/favicon.ico" width="400" alt="Logo">
</p>

[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

Zarban SDK is a Go interface for interacting with the Zarban DeFi protocol, enabling developers to seamlessly integrate lending and borrowing functionalities into their applications. This SDK simplifies complex DeFi operations by providing easy-to-use methods for lending assets, managing collateral, borrowing funds, and monitoring positions in the Zarban protocol.

## Features

- **Automated API Client Generation**: Built using OpenAPI specification, ensuring type safety and up-to-date API compatibility
- **Lending Operations**: Easily deposit assets, view lending rates, and manage lending positions
- **Borrowing Management**: Streamlined methods for borrowing assets, managing collateral, and monitoring loan health
- **Position Tracking**: Real-time access to user positions, including borrowed amounts, collateral ratios, and liquidation thresholds
- **Market Data**: Simple methods to fetch current interest rates, available liquidity, and market statistics
- **Type Safety**: Full type hints support for Go static type checking
- **Error Handling**: Comprehensive error handling with detailed exceptions for DeFi operations
- **Async Support**: Asynchronous methods for improved performance in high-throughput applications

## Environments

Zarban SDK supports two distinct environments:

1. **Mainnet**: The production environment for the Zarban DeFi protocol.

- Wallet API: `https://wapi.zarban.io`
- Service API: `https://api.zarban.io`

2. **Testnet**: A separate testing environment for the Zarban protocol.
- Wallet API: `https://testwapi.zarban.io`
- Service API: `https://testapi.zarban.io`

Be sure to use the appropriate environment configuration when interacting with the Zarban SDK.

## Installation

```bash
go get github.com/zarbanio/zarban-go
```

## Quick Start

Zarban SDK provides access to two distinct APIs:

### 1. Wallet API (`zarban.wallet`)

The Wallet API handles user authentication and wallet management operations.

### 2. Service API(`zarban.service`)

The Zarban Service API provides access to core DeFi protocol operations.

```go
import (
"context"
"log"

"github.com/zarbanio/zarban-go/wallet"
)

client, err := wallet.NewClient("https://testwapi.zarban.io")
if err != nil {
log.Fatalf("Failed to create wallet client: %v", err)
return
}

httpResponse, err := client.someMethod(context.Background())
if err != nil {
log.Fatalf("Error during API call: %v", err)
return
}
```

## Usage Examples

For detailed usage examples, see our [Examples Documentation](docs/examples).

### Advanced Usage

Here's a simple example to sign up and get started with Zarban:

```go
import (
"context"
"fmt"
"log"

"github.com/zarbanio/zarban-go/wallet"
)

func SignupExample() {
// Create and configure the client
client, err := wallet.NewClient("https://testwapi.zarban.io")
if err != nil {
log.Fatalf("Failed to create wallet client: %v", err)
return
}
// Prepare the signup request data
signUpRequest := wallet.SignUpRequest{
Email: "[email protected]",
Password: "yourSecurePassword",
}

httpResponse, err := client.SignupWithEmailAndPassword(context.Background(), signUpRequest)
if err != nil {
log.Fatalf("Error during API call: %v", err)
return
}

var successResponse wallet.SimpleResponse
err = wallet.HandleAPIResponse(context.Background(), httpResponse, &successResponse)
if err != nil {
if apiErr, ok := err.(*wallet.APIError); ok {
fmt.Println(wallet.PrettyPrintError(apiErr))
} else {
log.Printf("Unexpected error: %v", err)
}
return
}

fmt.Printf("Signup successful: %+v\n", successResponse.Messages)
}
```

## Configuration

The SDK can be configured with various options to customize its behavior and authentication methods.

### Basic Configuration

```Go
import "github.com/zarbanio/zarban-go/wallet"

// Basic configuration with just the host URL
client, err := wallet.NewClient("https://testwapi.zarban.io")
if err != nil {
log.Fatalf("Failed to create wallet client: %v", err)
return
}
```

### Authentication Options

The SDK supports multiple authentication methods:

1. API Key Authentication:

```Go
// Define headers to be added
headers := map[string]string{
"Authorization": "Bearer " + loginResponse.Token,
}

// configure it with the header editing function
client, err = wallet.NewClient(
"https://testwapi.zarban.io",
wallet.WithRequestEditorFn(wallet.AddHeaders(headers)),
)
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
```

## Error Handling

To make error handling easier, we provide a utility function named HandleAPIResponse. This function simplifies the process of managing errors and helps avoid repetitive if/else(or switch/case) blocks in your code.

While using HandleAPIResponse is not mandatory, we highly recommend it for cleaner and more maintainable code. If you prefer, you can always handle errors manually using traditional if/else(or switch/case) blocks.

### Usage example:

Using HandleAPIResponse

```go
httpResponse, err = client.CreateChildUser(context.Background(), createChildUserRequest)
if err != nil {
log.Fatalf("Error during API call -> CreateChildUser: %v", err)
return
}

var createChildResponse wallet.User
err = wallet.HandleAPIResponse(context.Background(), httpResponse, &createChildResponse)
if err != nil {
if apiErr, ok := err.(*wallet.APIError); ok {
fmt.Println(wallet.PrettyPrintError(apiErr))
} else {
log.Printf("Unexpected error: %v", err)
}
return
}
```

Manual Error Handling

```go
httpResponse, err = client.CreateChildUser(context.Background(), createChildUserRequest)
if err != nil {
log.Fatalf("Error during API call: %v", err)
return
}

createChildResponse, err := wallet.ParseCreateChildUserResponse(httpResponse)
if err != nil {
log.Fatalf("Error while parsing http response: %v", err)
return
}

switch c.StatusCode() {
case 200:
fmt.Printf("Child user created successfully. User: %s\n", *c.JSON200.Username)
return c.JSON200, nil
case 400:
return c.JSON400, fmt.Errorf("bad request: %s", c.JSON400.Msg)
case 500:
return c.JSON500, fmt.Errorf("internal server error: %s", c.JSON500.Msg)
default:
return nil, fmt.Errorf("unexpected status code: %d", c.StatusCode())
}
```

## Contributing

We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.

1. Fork the repository
2. Create a new branch
3. Make your changes
4. Submit a pull request

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Support

- Create an issue on GitHub
- Email: [email protected]
- Documentation: [https://docs.zarban.io](https://docs.zarban.io)
Binary file added assets/zarban.ico
Binary file not shown.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
18 changes: 18 additions & 0 deletions docs/service/Account.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Account

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**points** | **int** | The number of points the account has. |
**address** | **str** | Ethereum address of the account |
**wallet_balance** | [**WalletBalance**](WalletBalance.md) | |
**net_worth** | **dict(str, str)** | |
**total_debt** | **dict(str, str)** | |
**total_deposits** | **dict(str, str)** | |
**lendingpool_summary** | [**AccountLendingpoolSummary**](AccountLendingpoolSummary.md) | |
**stabelcoin_system_summary** | [**AccountStablecoinSystemSummary**](AccountStablecoinSystemSummary.md) | |
**staking_summary** | [**AccountStakingSummary**](AccountStakingSummary.md) | |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


20 changes: 20 additions & 0 deletions docs/service/AccountLendingpoolSummary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# AccountLendingpoolSummary

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**total_debt** | **dict(str, str)** | |
**total_deposits** | **dict(str, str)** | |
**total_collateral** | **dict(str, str)** | |
**health_factor** | **str** | Health factor in lending pool |
**net_apy** | **str** | Net annual percentage yield in lending pool |
**total_supply_apy** | **str** | Total supply rate in lending pool for account |
**total_borrow_apy** | **str** | Total borrow rate in lending pool for account |
**available_to_borrow** | **dict(str, str)** | |
**borrow_power_used** | **str** | Borrow power used in lending pool |
**current_liquidation_threshold** | **str** | Current liquidation threshold in lending pool |
**loan_to_value** | **str** | Loan to value in lending pool |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


12 changes: 12 additions & 0 deletions docs/service/AccountStablecoinSystemSummary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# AccountStablecoinSystemSummary

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**total_debt** | **dict(str, str)** | |
**total_deposits** | **dict(str, str)** | |
**net_apy** | **str** | Net annual percentage yield in stablecoin system |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


Loading

0 comments on commit 8d2fc1c

Please sign in to comment.