zo-sdk 0.0.3 → 0.0.5
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 +153 -0
- package/package.json +17 -5
- package/LICENSE +0 -21
- package/jest.config.js +0 -7
package/README.md
CHANGED
|
@@ -1 +1,154 @@
|
|
|
1
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
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zo-sdk",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.5",
|
|
4
|
+
"description": "",
|
|
5
5
|
"author": "",
|
|
6
|
-
"license": "
|
|
6
|
+
"license": "ISC",
|
|
7
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
|
+
},
|
|
8
20
|
"main": "./dist/index.cjs",
|
|
9
21
|
"module": "./dist/index.mjs",
|
|
10
22
|
"types": "dist/index.d.ts",
|
|
@@ -12,7 +24,6 @@
|
|
|
12
24
|
"build": "ts-bridge build --project ./tsconfig.json --clean",
|
|
13
25
|
"serve": "tsx dist/index.js",
|
|
14
26
|
"start": "tsx src/index.ts",
|
|
15
|
-
"pub": "tsc && npm publish",
|
|
16
27
|
"test": "vitest"
|
|
17
28
|
},
|
|
18
29
|
"dependencies": {
|
|
@@ -24,6 +35,7 @@
|
|
|
24
35
|
"decimal.js": "10.4.3"
|
|
25
36
|
},
|
|
26
37
|
"devDependencies": {
|
|
27
|
-
"@ts-bridge/cli": "^0.6.3"
|
|
38
|
+
"@ts-bridge/cli": "^0.6.3",
|
|
39
|
+
"typescript": "^5.0.0"
|
|
28
40
|
}
|
|
29
41
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Zo Finance
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|