zo-sdk 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # zo-sdk
2
+
3
+ A TypeScript SDK for interacting with the Zo Protocol on Sui Network.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install zo-sdk
9
+ # or
10
+ yarn add zo-sdk
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import { API, Network } from 'zo-sdk'
17
+ import { SuiClient } from '@mysten/sui/client'
18
+
19
+ // Initialize the API
20
+ const provider = new SuiClient({ url: 'https://sui-rpc.url' })
21
+ const api = API.getInstance(
22
+ Network.MAINNET,
23
+ provider,
24
+ 'https://api-endpoint',
25
+ 'https://price-feed-url'
26
+ )
27
+
28
+ // Example: Get market information
29
+ const marketInfo = await api.getMarketInfo()
30
+
31
+ // Example: Get oracle price for a token
32
+ const price = await api.getOraclePrice('sui')
33
+ ```
34
+
35
+ ## Key Features
36
+
37
+ ### Market Operations
38
+
39
+ ```typescript
40
+ // Deposit tokens to get ZLP
41
+ const tx = await api.deposit(
42
+ 'sui', // token
43
+ ['coinObjectId'], // coin object IDs
44
+ 1000000, // amount
45
+ 0 // minimum amount out
46
+ )
47
+
48
+ // Withdraw tokens by burning ZLP
49
+ const tx = await api.withdraw(
50
+ 'sui', // token
51
+ ['zlpCoinObjectId'], // ZLP coin object IDs
52
+ 1000000, // amount
53
+ 0 // minimum amount out
54
+ )
55
+
56
+ // Swap tokens
57
+ const tx = await api.swap(
58
+ 'sui', // from token
59
+ 'usdc', // to token
60
+ BigInt(1000000), // amount
61
+ ['coinObjectId'] // coin object IDs
62
+ )
63
+ ```
64
+
65
+ ### Trading Operations
66
+
67
+ ```typescript
68
+ // Open a position
69
+ const tx = await api.openPosition(
70
+ 'sui', // collateral token
71
+ 'btc', // index token
72
+ BigInt(1000000), // size
73
+ BigInt(100000), // collateral amount
74
+ ['coinObjectId'], // coin object IDs
75
+ true, // long position
76
+ BigInt(100000), // reserve amount
77
+ 30000, // index price
78
+ 1.5, // collateral price
79
+ 0.003 // slippage
80
+ )
81
+
82
+ // Decrease a position
83
+ const tx = await api.decreasePosition(
84
+ 'positionCapId',
85
+ 'sui', // collateral token
86
+ 'btc', // index token
87
+ BigInt(500000), // amount to decrease
88
+ true, // long position
89
+ 30000, // index price
90
+ 1.5, // collateral price
91
+ )
92
+
93
+ // Cancel an order
94
+ const tx = await api.cancelOrder(
95
+ 'orderCapId',
96
+ 'sui',
97
+ 'btc',
98
+ true, // long position
99
+ 'OPEN_POSITION' // order type
100
+ )
101
+ ```
102
+
103
+ ### Data Queries
104
+
105
+ ```typescript
106
+ // Get position information
107
+ const positions = await api.getPositionInfoList(positionCapInfoList, 'ownerAddress')
108
+
109
+ // Get order information
110
+ const orders = await api.getOrderInfoList(orderCapInfoList, 'ownerAddress')
111
+
112
+ // Get vault information
113
+ const vaultInfo = await api.getVaultInfo('sui')
114
+
115
+ // Get symbol information
116
+ const symbolInfo = await api.getSymbolInfo('btc', true) // true for long
117
+
118
+ // Get market valuation
119
+ const valuation = await api.valuateMarket()
120
+ ```
121
+
122
+ ### Staking Operations
123
+
124
+ ```typescript
125
+ // Stake ZLP
126
+ const tx = await api.stake(
127
+ ['zlpCoinObjectId'],
128
+ BigInt(1000000),
129
+ 'poolId'
130
+ )
131
+
132
+ // Unstake ZLP
133
+ const tx = await api.unstake(
134
+ credentials,
135
+ BigInt(1000000),
136
+ 'poolId'
137
+ )
138
+ ```
139
+
140
+ ## Error Handling
141
+
142
+ The SDK throws errors for invalid operations and network issues. Always wrap API calls in try-catch blocks:
143
+
144
+ ```typescript
145
+ try {
146
+ const marketInfo = await api.getMarketInfo()
147
+ } catch (error) {
148
+ console.error('Failed to get market info:', error)
149
+ }
150
+ ```
151
+
152
+ ## Documentation
153
+
154
+ For detailed API documentation and advanced usage, please refer to the source code and comments.
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "zo-sdk",
3
+ "version": "0.0.4",
4
+ "description": "",
5
+ "author": "",
6
+ "license": "ISC",
7
+ "keywords": [],
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.mts",
12
+ "default": "./dist/index.mjs"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.cts",
16
+ "default": "./dist/index.cjs"
17
+ }
18
+ }
19
+ },
20
+ "main": "./dist/index.cjs",
21
+ "module": "./dist/index.mjs",
22
+ "types": "dist/index.d.ts",
23
+ "scripts": {
24
+ "build": "ts-bridge build --project ./tsconfig.json --clean",
25
+ "serve": "tsx dist/index.js",
26
+ "start": "tsx src/index.ts",
27
+ "test": "vitest"
28
+ },
29
+ "dependencies": {
30
+ "@mysten/bcs": "0.7.1",
31
+ "@mysten/sui": "^1.14.3",
32
+ "@mysten/wallet-standard": "0.6.0",
33
+ "@pythnetwork/hermes-client": "^1.2.0",
34
+ "@pythnetwork/pyth-sui-js": "2.1.0",
35
+ "decimal.js": "10.4.3"
36
+ },
37
+ "devDependencies": {
38
+ "@ts-bridge/cli": "^0.6.3"
39
+ }
40
+ }