Zarban SDK is a typeScript 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 typeScript 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.
npm install zarban
or:
yarn install zarban
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 { Wallet } from "zarban";
// Initialize the client
const cfg = Wallet.Configuration({
basePath: "https://testwapi.zarban.io",
});
const authApi = new Wallet.AuthApi.AuthApi(cfg);
// Make a simple API call
try{
response = await authApi.someMethod()
console.log(response)
}catch(error){
console.log(error)
}
For detailed usage examples, see our Examples Documentation.
Here's a simple example to sign up and get started with Zarban:
import { Wallet, ZarbanUtils } from "zarban";
const { withErrorHandler } = ZarbanUtils;
async function signupExample() {
// Create and configure the Configuration object
const cfg = new Wallet.Configuration({
basePath: "https://testwapi.zarban.io",
});
// Create an instance of the authApi using the Configuration
const authApi = new Wallet.AuthApi.AuthApi(cfg);
// Prepare the signup request data
const signupRequest: Wallet.SignUpRequest = {
email: "[email protected]",
password: "yourSecurePassword",
};
const signupWithHandler = withErrorHandler<Wallet.SimpleResponse>(
"Wallet",
() => authApi.signupWithEmailAndPassword(signupRequest),
(response) => {
console.log("Signup successful!");
console.log("Confirmation link sent.");
console.log(
`Message: ${JSON.stringify(response.data.messages, null, 2)}`
);
}
);
const [result, error] = await signupWithHandler();
if (error) {
// You can do some extra work with errors here!
return error;
}
return result;
}
// Execute with proper error handling
if (require.main === module) {
signupExample().then((result) => {
if (result instanceof Error) {
process.exit(1);
}
process.exit(0);
});
}
The SDK can be configured with various options to customize its behavior and authentication methods.
import { Wallet } from "zarban";
// Basic configuration with just the host URL
const cfg = new Wallet.Configuration({
basePath: "https://testwapi.zarban.io",
});
The SDK supports multiple authentication methods:
- API Key Authentication:
const cfg = new Wallet.Configuration({
basePath: "https://testwapi.zarban.io",
apiKey: {"APIKeyAuth": "your-api-key-here"},
});
- Basic Authentication:
const cfg = new Wallet.Configuration({
basePath: "https://testwapi.zarban.io",
username: "your-username",
password: "your-password"
});
Parameter | Type | Description |
---|---|---|
apiKey | string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>) |
Parameter for apiKey security. Can be a string, Promise of string, or function returning string/Promise. |
username | string |
Parameter for basic security authentication username. |
password | string |
Parameter for basic security authentication password. |
accessToken | string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>) |
Parameter for OAuth2 security. Can be a string, Promise of string, or function taking optional name and scopes. |
basePath | string |
Override the default base path for API requests. |
serverIndex | number |
Override the default server index for API requests. |
baseOptions | any |
Base options to be applied to all axios calls. |
formDataCtor | new () => any |
Custom FormData constructor for environments that don't support the native FormData class. |
To make error handling easier, we provide a utility function named withErrorHandler. This function simplifies the process of managing errors and helps avoid repetitive try/catch blocks in your code.
While using withErrorHandler is not mandatory, we highly recommend it for cleaner and more maintainable code. If you prefer, you can always handle errors manually using traditional try/catch blocks.
Using withErrorHandler
import { ZarbanUtils } from "zarban";
const { withErrorHandler } = ZarbanUtils;
const loginWithHandler = withErrorHandler<Wallet.JwtResponse>(
"Wallet",
() => authApi.loginWithEmailAndPassword(loginRequest),
(response) => {
console.log("Login successful!");
console.log(`Token: ${response.data.token}`);
}
);
const [response, error] = await loginWithHandler();
if (error) {
// you can do some addition works with error here!
return error;
}
Manual Error Handling
try{
const response = await authApi.loginWithEmailAndPassword(loginRequest)
console.log("Login successful!");
console.log(`Token: ${response.data.token}`);
}catch(error){
// handle different types of error here
console.log(error)
}
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