upers-sdk
v0.0.1
Published
A TypeScript SDK for interacting with the ZO Protocol on Sui Network.
Readme
upers-sdk
A TypeScript SDK for interacting with the ZO Protocol on Sui Network.
Installation
npm install upers-sdk
# or
yarn add upers-sdkQuick Start
import { API, Network } from 'upers-sdk'
import { SuiClient } from '@mysten/sui/client'
// Initialize the API
const provider = new SuiClient({ url: 'https://sui-rpc.url' })
const api = API.getInstance(
Network.MAINNET,
provider,
'https://api-endpoint',
'https://price-feed-url'
)
// Example: Get market information
const marketInfo = await api.getMarketInfo()
// Example: Get oracle price for a token
const price = await api.getOraclePrice('sui')Key Features
Market Operations
// Deposit tokens to get upers
const tx = await api.deposit(
'sui', // token
['coinObjectId'], // coin object IDs
1000000, // amount
0 // minimum amount out
)
// Withdraw tokens by burning upers
const tx = await api.withdraw(
'sui', // token
['upersCoinObjectId'], // upers coin object IDs
1000000, // amount
0 // minimum amount out
)
// Swap tokens
const tx = await api.swap(
'sui', // from token
'usdc', // to token
BigInt(1000000), // amount
['coinObjectId'] // coin object IDs
)Trading Operations
// Open a position
const tx = await api.openPosition(
'sui', // collateral token
'btc', // index token
BigInt(1000000), // size
BigInt(100000), // collateral amount
['coinObjectId'], // coin object IDs
true, // long position
BigInt(100000), // reserve amount
30000, // index price
1.5, // collateral price
0.003 // slippage
)
// Decrease a position
const tx = await api.decreasePosition(
'positionCapId',
'sui', // collateral token
'btc', // index token
BigInt(500000), // amount to decrease
true, // long position
30000, // index price
1.5, // collateral price
)
// Cancel an order
const tx = await api.cancelOrder(
'orderCapId',
'sui',
'btc',
true, // long position
'OPEN_POSITION' // order type
)Data Queries
// Get position information
const positions = await api.getPositionInfoList(positionCapInfoList, 'ownerAddress')
// Get order information
const orders = await api.getOrderInfoList(orderCapInfoList, 'ownerAddress')
// Get vault information
const vaultInfo = await api.getVaultInfo('sui')
// Get symbol information
const symbolInfo = await api.getSymbolInfo('btc', true) // true for long
// Get market valuation
const valuation = await api.valuateMarket()Error Handling
The SDK throws errors for invalid operations and network issues. Always wrap API calls in try-catch blocks:
try {
const marketInfo = await api.getMarketInfo()
} catch (error) {
console.error('Failed to get market info:', error)
}Documentation
For detailed API documentation and advanced usage, please refer to the source code and comments.
