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.
- 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
Zarban SDK supports two distinct environments:
-
Mainnet: The production environment for the Zarban DeFi protocol.
- Wallet API:
https://wapi.zarban.io
- Service API:
https://api.zarban.io
- Wallet API:
-
Testnet: A separate testing environment for the Zarban protocol.
- Wallet API:
https://testwapi.zarban.io
- Service API:
https://testapi.zarban.io
- Wallet API:
Be sure to use the appropriate environment configuration when interacting with the Zarban SDK.
go get github.com/zarbanio/zarban-go
Zarban SDK provides access to two distinct APIs:
The Wallet API handles user authentication and wallet management operations.
The Zarban Service API provides access to core DeFi protocol operations.
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
}
For detailed usage examples, see our Examples Documentation.
Here's a simple example to sign up and get started with Zarban:
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)
}
The SDK can be configured with various options to customize its behavior and authentication methods.
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
}
The SDK supports multiple authentication methods:
- API Key Authentication:
// 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)
}
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.
Using HandleAPIResponse
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
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())
}
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a new branch
- Make your changes
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Create an issue on GitHub
- Email: [email protected]
- Documentation: https://docs.zarban.io