@zofai/zo-sdk 0.1.92
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/.claude/settings.local.json +9 -0
- package/.gitattributes +4 -0
- package/.prettierrc.js +9 -0
- package/README.md +28 -0
- package/dist/abstract/BaseAPI.cjs +206 -0
- package/dist/abstract/BaseAPI.cjs.map +1 -0
- package/dist/abstract/BaseAPI.d.cts +172 -0
- package/dist/abstract/BaseAPI.d.cts.map +1 -0
- package/dist/abstract/BaseAPI.d.mts +172 -0
- package/dist/abstract/BaseAPI.d.mts.map +1 -0
- package/dist/abstract/BaseAPI.mjs +202 -0
- package/dist/abstract/BaseAPI.mjs.map +1 -0
- package/dist/abstract/BaseDataAPI.cjs +140 -0
- package/dist/abstract/BaseDataAPI.cjs.map +1 -0
- package/dist/abstract/BaseDataAPI.d.cts +89 -0
- package/dist/abstract/BaseDataAPI.d.cts.map +1 -0
- package/dist/abstract/BaseDataAPI.d.mts +89 -0
- package/dist/abstract/BaseDataAPI.d.mts.map +1 -0
- package/dist/abstract/BaseDataAPI.mjs +136 -0
- package/dist/abstract/BaseDataAPI.mjs.map +1 -0
- package/dist/abstract/index.cjs +12 -0
- package/dist/abstract/index.cjs.map +1 -0
- package/dist/abstract/index.d.cts +7 -0
- package/dist/abstract/index.d.cts.map +1 -0
- package/dist/abstract/index.d.mts +7 -0
- package/dist/abstract/index.d.mts.map +1 -0
- package/dist/abstract/index.mjs +7 -0
- package/dist/abstract/index.mjs.map +1 -0
- package/dist/api.cjs +779 -0
- package/dist/api.cjs.map +1 -0
- package/dist/api.d.cts +75 -0
- package/dist/api.d.cts.map +1 -0
- package/dist/api.d.mts +75 -0
- package/dist/api.d.mts.map +1 -0
- package/dist/api.mjs +775 -0
- package/dist/api.mjs.map +1 -0
- package/dist/bcs.cjs +42 -0
- package/dist/bcs.cjs.map +1 -0
- package/dist/bcs.d.cts +91 -0
- package/dist/bcs.d.cts.map +1 -0
- package/dist/bcs.d.mts +91 -0
- package/dist/bcs.d.mts.map +1 -0
- package/dist/bcs.mjs +39 -0
- package/dist/bcs.mjs.map +1 -0
- package/dist/consts/deployments-shared-mainnet.json +50 -0
- package/dist/consts/deployments-shared-testnet.json +45 -0
- package/dist/consts/deployments-slp-mainnet.json +600 -0
- package/dist/consts/deployments-slp-testnet.json +87 -0
- package/dist/consts/deployments-usdz-mainnet.json +494 -0
- package/dist/consts/deployments-usdz-testnet.json +98 -0
- package/dist/consts/deployments-zbtcvc-mainnet.json +180 -0
- package/dist/consts/deployments-zlp-mainnet.json +791 -0
- package/dist/consts/deployments-zlp-testnet.json +76 -0
- package/dist/consts/index.cjs +200 -0
- package/dist/consts/index.cjs.map +1 -0
- package/dist/consts/index.d.cts +157 -0
- package/dist/consts/index.d.cts.map +1 -0
- package/dist/consts/index.d.mts +157 -0
- package/dist/consts/index.d.mts.map +1 -0
- package/dist/consts/index.mjs +189 -0
- package/dist/consts/index.mjs.map +1 -0
- package/dist/consts/price_id_to_object_id.mainnet.json +56 -0
- package/dist/consts/price_id_to_object_id.testnet.json +17 -0
- package/dist/data.cjs +919 -0
- package/dist/data.cjs.map +1 -0
- package/dist/data.d.cts +235 -0
- package/dist/data.d.cts.map +1 -0
- package/dist/data.d.mts +235 -0
- package/dist/data.d.mts.map +1 -0
- package/dist/data.mjs +915 -0
- package/dist/data.mjs.map +1 -0
- package/dist/factory/SDKFactory.cjs +228 -0
- package/dist/factory/SDKFactory.cjs.map +1 -0
- package/dist/factory/SDKFactory.d.cts +84 -0
- package/dist/factory/SDKFactory.d.cts.map +1 -0
- package/dist/factory/SDKFactory.d.mts +84 -0
- package/dist/factory/SDKFactory.d.mts.map +1 -0
- package/dist/factory/SDKFactory.mjs +222 -0
- package/dist/factory/SDKFactory.mjs.map +1 -0
- package/dist/implementations/SLPAPI.cjs +1794 -0
- package/dist/implementations/SLPAPI.cjs.map +1 -0
- package/dist/implementations/SLPAPI.d.cts +183 -0
- package/dist/implementations/SLPAPI.d.cts.map +1 -0
- package/dist/implementations/SLPAPI.d.mts +183 -0
- package/dist/implementations/SLPAPI.d.mts.map +1 -0
- package/dist/implementations/SLPAPI.mjs +1790 -0
- package/dist/implementations/SLPAPI.mjs.map +1 -0
- package/dist/implementations/SLPDataAPI.cjs +1384 -0
- package/dist/implementations/SLPDataAPI.cjs.map +1 -0
- package/dist/implementations/SLPDataAPI.d.cts +158 -0
- package/dist/implementations/SLPDataAPI.d.cts.map +1 -0
- package/dist/implementations/SLPDataAPI.d.mts +158 -0
- package/dist/implementations/SLPDataAPI.d.mts.map +1 -0
- package/dist/implementations/SLPDataAPI.mjs +1380 -0
- package/dist/implementations/SLPDataAPI.mjs.map +1 -0
- package/dist/implementations/USDZAPI.cjs +1676 -0
- package/dist/implementations/USDZAPI.cjs.map +1 -0
- package/dist/implementations/USDZAPI.d.cts +180 -0
- package/dist/implementations/USDZAPI.d.cts.map +1 -0
- package/dist/implementations/USDZAPI.d.mts +180 -0
- package/dist/implementations/USDZAPI.d.mts.map +1 -0
- package/dist/implementations/USDZAPI.mjs +1672 -0
- package/dist/implementations/USDZAPI.mjs.map +1 -0
- package/dist/implementations/USDZDataAPI.cjs +1209 -0
- package/dist/implementations/USDZDataAPI.cjs.map +1 -0
- package/dist/implementations/USDZDataAPI.d.cts +191 -0
- package/dist/implementations/USDZDataAPI.d.cts.map +1 -0
- package/dist/implementations/USDZDataAPI.d.mts +191 -0
- package/dist/implementations/USDZDataAPI.d.mts.map +1 -0
- package/dist/implementations/USDZDataAPI.mjs +1205 -0
- package/dist/implementations/USDZDataAPI.mjs.map +1 -0
- package/dist/implementations/ZBTCVCAPI.cjs +906 -0
- package/dist/implementations/ZBTCVCAPI.cjs.map +1 -0
- package/dist/implementations/ZBTCVCAPI.d.cts +107 -0
- package/dist/implementations/ZBTCVCAPI.d.cts.map +1 -0
- package/dist/implementations/ZBTCVCAPI.d.mts +107 -0
- package/dist/implementations/ZBTCVCAPI.d.mts.map +1 -0
- package/dist/implementations/ZBTCVCAPI.mjs +902 -0
- package/dist/implementations/ZBTCVCAPI.mjs.map +1 -0
- package/dist/implementations/ZBTCVCDataAPI.cjs +829 -0
- package/dist/implementations/ZBTCVCDataAPI.cjs.map +1 -0
- package/dist/implementations/ZBTCVCDataAPI.d.cts +94 -0
- package/dist/implementations/ZBTCVCDataAPI.d.cts.map +1 -0
- package/dist/implementations/ZBTCVCDataAPI.d.mts +94 -0
- package/dist/implementations/ZBTCVCDataAPI.d.mts.map +1 -0
- package/dist/implementations/ZBTCVCDataAPI.mjs +825 -0
- package/dist/implementations/ZBTCVCDataAPI.mjs.map +1 -0
- package/dist/implementations/ZLPAPI.cjs +1948 -0
- package/dist/implementations/ZLPAPI.cjs.map +1 -0
- package/dist/implementations/ZLPAPI.d.cts +192 -0
- package/dist/implementations/ZLPAPI.d.cts.map +1 -0
- package/dist/implementations/ZLPAPI.d.mts +192 -0
- package/dist/implementations/ZLPAPI.d.mts.map +1 -0
- package/dist/implementations/ZLPAPI.mjs +1944 -0
- package/dist/implementations/ZLPAPI.mjs.map +1 -0
- package/dist/implementations/ZLPDataAPI.cjs +1267 -0
- package/dist/implementations/ZLPDataAPI.cjs.map +1 -0
- package/dist/implementations/ZLPDataAPI.d.cts +193 -0
- package/dist/implementations/ZLPDataAPI.d.cts.map +1 -0
- package/dist/implementations/ZLPDataAPI.d.mts +193 -0
- package/dist/implementations/ZLPDataAPI.d.mts.map +1 -0
- package/dist/implementations/ZLPDataAPI.mjs +1263 -0
- package/dist/implementations/ZLPDataAPI.mjs.map +1 -0
- package/dist/implementations/index.cjs +26 -0
- package/dist/implementations/index.cjs.map +1 -0
- package/dist/implementations/index.d.cts +13 -0
- package/dist/implementations/index.d.cts.map +1 -0
- package/dist/implementations/index.d.mts +13 -0
- package/dist/implementations/index.d.mts.map +1 -0
- package/dist/implementations/index.mjs +15 -0
- package/dist/implementations/index.mjs.map +1 -0
- package/dist/index.cjs +69 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +51 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +51 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +51 -0
- package/dist/index.mjs.map +1 -0
- package/dist/interfaces/base.cjs +7 -0
- package/dist/interfaces/base.cjs.map +1 -0
- package/dist/interfaces/base.d.cts +346 -0
- package/dist/interfaces/base.d.cts.map +1 -0
- package/dist/interfaces/base.d.mts +346 -0
- package/dist/interfaces/base.d.mts.map +1 -0
- package/dist/interfaces/base.mjs +6 -0
- package/dist/interfaces/base.mjs.map +1 -0
- package/dist/interfaces/index.cjs +31 -0
- package/dist/interfaces/index.cjs.map +1 -0
- package/dist/interfaces/index.d.cts +15 -0
- package/dist/interfaces/index.d.cts.map +1 -0
- package/dist/interfaces/index.d.mts +15 -0
- package/dist/interfaces/index.d.mts.map +1 -0
- package/dist/interfaces/index.mjs +15 -0
- package/dist/interfaces/index.mjs.map +1 -0
- package/dist/interfaces/slp.cjs +7 -0
- package/dist/interfaces/slp.cjs.map +1 -0
- package/dist/interfaces/slp.d.cts +179 -0
- package/dist/interfaces/slp.d.cts.map +1 -0
- package/dist/interfaces/slp.d.mts +179 -0
- package/dist/interfaces/slp.d.mts.map +1 -0
- package/dist/interfaces/slp.mjs +6 -0
- package/dist/interfaces/slp.mjs.map +1 -0
- package/dist/interfaces/usdz.cjs +7 -0
- package/dist/interfaces/usdz.cjs.map +1 -0
- package/dist/interfaces/usdz.d.cts +104 -0
- package/dist/interfaces/usdz.d.cts.map +1 -0
- package/dist/interfaces/usdz.d.mts +104 -0
- package/dist/interfaces/usdz.d.mts.map +1 -0
- package/dist/interfaces/usdz.mjs +6 -0
- package/dist/interfaces/usdz.mjs.map +1 -0
- package/dist/interfaces/zbtcvc.cjs +7 -0
- package/dist/interfaces/zbtcvc.cjs.map +1 -0
- package/dist/interfaces/zbtcvc.d.cts +64 -0
- package/dist/interfaces/zbtcvc.d.cts.map +1 -0
- package/dist/interfaces/zbtcvc.d.mts +64 -0
- package/dist/interfaces/zbtcvc.d.mts.map +1 -0
- package/dist/interfaces/zbtcvc.mjs +6 -0
- package/dist/interfaces/zbtcvc.mjs.map +1 -0
- package/dist/interfaces/zlp.cjs +7 -0
- package/dist/interfaces/zlp.cjs.map +1 -0
- package/dist/interfaces/zlp.d.cts +114 -0
- package/dist/interfaces/zlp.d.cts.map +1 -0
- package/dist/interfaces/zlp.d.mts +114 -0
- package/dist/interfaces/zlp.d.mts.map +1 -0
- package/dist/interfaces/zlp.mjs +6 -0
- package/dist/interfaces/zlp.mjs.map +1 -0
- package/dist/oracle.cjs +118 -0
- package/dist/oracle.cjs.map +1 -0
- package/dist/oracle.d.cts +25 -0
- package/dist/oracle.d.cts.map +1 -0
- package/dist/oracle.d.mts +25 -0
- package/dist/oracle.d.mts.map +1 -0
- package/dist/oracle.mjs +114 -0
- package/dist/oracle.mjs.map +1 -0
- package/dist/utils.cjs +129 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +44 -0
- package/dist/utils.d.cts.map +1 -0
- package/dist/utils.d.mts +44 -0
- package/dist/utils.d.mts.map +1 -0
- package/dist/utils.mjs +115 -0
- package/dist/utils.mjs.map +1 -0
- package/docs/SUMMARY.md +10 -0
- package/docs/api-reference.md +32 -0
- package/docs/architecture.md +14 -0
- package/docs/common-operations.md +52 -0
- package/docs/error-handling.md +17 -0
- package/docs/getting-started.md +60 -0
- package/docs/introduction.md +15 -0
- package/docs/lp-specific-features.md +96 -0
- package/docs/type-safety.md +29 -0
- package/eslint.config.mjs +18 -0
- package/package.json +42 -0
- package/src/abstract/BaseAPI.ts +575 -0
- package/src/abstract/BaseDataAPI.ts +207 -0
- package/src/abstract/index.ts +7 -0
- package/src/api.ts +1100 -0
- package/src/bcs.ts +45 -0
- package/src/consts/deployments-shared-mainnet.json +50 -0
- package/src/consts/deployments-shared-testnet.json +45 -0
- package/src/consts/deployments-slp-mainnet.json +600 -0
- package/src/consts/deployments-slp-testnet.json +87 -0
- package/src/consts/deployments-usdz-mainnet.json +494 -0
- package/src/consts/deployments-usdz-testnet.json +98 -0
- package/src/consts/deployments-zbtcvc-mainnet.json +180 -0
- package/src/consts/deployments-zlp-mainnet.json +791 -0
- package/src/consts/deployments-zlp-testnet.json +76 -0
- package/src/consts/index.ts +345 -0
- package/src/consts/price_id_to_object_id.mainnet.json +56 -0
- package/src/consts/price_id_to_object_id.testnet.json +17 -0
- package/src/data.ts +1279 -0
- package/src/factory/SDKFactory.ts +340 -0
- package/src/implementations/SLPAPI.ts +2722 -0
- package/src/implementations/SLPDataAPI.ts +1839 -0
- package/src/implementations/USDZAPI.ts +2488 -0
- package/src/implementations/USDZDataAPI.ts +1548 -0
- package/src/implementations/ZBTCVCAPI.ts +1337 -0
- package/src/implementations/ZBTCVCDataAPI.ts +993 -0
- package/src/implementations/ZLPAPI.ts +2888 -0
- package/src/implementations/ZLPDataAPI.ts +1603 -0
- package/src/implementations/index.ts +16 -0
- package/src/index.ts +58 -0
- package/src/interfaces/base.ts +838 -0
- package/src/interfaces/index.ts +50 -0
- package/src/interfaces/slp.ts +268 -0
- package/src/interfaces/usdz.ts +181 -0
- package/src/interfaces/zbtcvc.ts +116 -0
- package/src/interfaces/zlp.ts +244 -0
- package/src/oracle.ts +153 -0
- package/src/utils.ts +168 -0
- package/tests/api.test.ts +219 -0
- package/tests/data.test.ts +156 -0
- package/tests/oracle.test.ts +33 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
## 1. Create an API or DataAPI instance
|
|
4
|
+
|
|
5
|
+
Use the **SDK** factory (exported as `SDK` from `zo-sdk`) to create LP-specific instances. You need a Sui client, network, API endpoint, and connection URL.
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { SDK, LPToken, Network } from 'zo-sdk'
|
|
9
|
+
import { SuiClient } from '@mysten/sui/client'
|
|
10
|
+
|
|
11
|
+
const provider = new SuiClient({ url: 'https://fullnode.mainnet.sui.io' })
|
|
12
|
+
const network = Network.MAINNET
|
|
13
|
+
const apiEndpoint = 'https://api.zo.xyz'
|
|
14
|
+
const connectionURL = 'wss://api.zo.xyz/ws'
|
|
15
|
+
|
|
16
|
+
// Create API instances (transactions + data)
|
|
17
|
+
const zlpAPI = SDK.createZLPAPI(network, provider, apiEndpoint, connectionURL)
|
|
18
|
+
const slpAPI = SDK.createSLPAPI(network, provider, apiEndpoint, connectionURL)
|
|
19
|
+
const usdzAPI = SDK.createUSDZAPI(network, provider, apiEndpoint, connectionURL)
|
|
20
|
+
|
|
21
|
+
// Or create by LP token enum
|
|
22
|
+
const api = SDK.createAPI(LPToken.ZLP, network, provider, apiEndpoint, connectionURL)
|
|
23
|
+
|
|
24
|
+
// Create DataAPI instances (read-only; no transaction methods)
|
|
25
|
+
const zlpDataAPI = SDK.createZLPDataAPI(network, provider, apiEndpoint, connectionURL)
|
|
26
|
+
const slpDataAPI = SDK.createSLPDataAPI(network, provider, apiEndpoint, connectionURL)
|
|
27
|
+
const usdzDataAPI = SDK.createUSDZDataAPI(network, provider, apiEndpoint, connectionURL)
|
|
28
|
+
|
|
29
|
+
// Or create DataAPI by LP token
|
|
30
|
+
const dataAPI = SDK.createDataAPI(LPToken.SLP, network, provider, apiEndpoint, connectionURL)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 2. API vs DataAPI
|
|
34
|
+
|
|
35
|
+
| Use case | Class | Use |
|
|
36
|
+
|----------|--------|-----|
|
|
37
|
+
| **Build transactions + read data** | **API** (`ZLPAPI`, `SLPAPI`, etc.) | Deposit, withdraw, open/close positions, stake, and also call data methods (market info, vaults, positions, etc.). |
|
|
38
|
+
| **Read-only** | **DataAPI** (`ZLPDataAPI`, `SLPDataAPI`, etc.) | Only query chain/API state (market valuation, vault info, positions, orders, history). No transaction building. |
|
|
39
|
+
|
|
40
|
+
**API** instances expose both transaction methods and data methods. Data methods (e.g. `getMarketInfo`, `valuateMarket`, `getVaultInfo`) are implemented by delegating to the internal `dataAPI`, so you can call them directly on the API or via `api.dataAPI`:
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
const zlpAPI = SDK.createZLPAPI(network, provider, apiEndpoint, connectionURL)
|
|
44
|
+
|
|
45
|
+
// Data methods are available directly on the API (same result either way)
|
|
46
|
+
const marketData = await zlpAPI.valuateMarket()
|
|
47
|
+
const marketDataAlt = await zlpAPI.dataAPI.valuateMarket()
|
|
48
|
+
|
|
49
|
+
// Transaction methods exist only on the API
|
|
50
|
+
const depositTx = await zlpAPI.deposit('usdc', ['coinId'], 1000000)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**DataAPI** instances are for read-only usage when you don't need to build transactions:
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
const zlpDataAPI = SDK.createZLPDataAPI(network, provider, apiEndpoint, connectionURL)
|
|
57
|
+
const marketData = await zlpDataAPI.valuateMarket()
|
|
58
|
+
const vaultInfo = await zlpDataAPI.getVaultInfo('usdc')
|
|
59
|
+
// zlpDataAPI.deposit(...) does not exist
|
|
60
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Introduction
|
|
2
|
+
|
|
3
|
+
ZO SDK is a TypeScript SDK for interacting with multiple LP tokens on Sui Network: **ZLP** (ZO Liquidity Provider), **SLP** (Sudo Liquidity Provider), and **USDZ** (USD Stablecoin).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install zo-sdk
|
|
9
|
+
# or
|
|
10
|
+
yarn add zo-sdk
|
|
11
|
+
# or
|
|
12
|
+
pnpm add zo-sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
For the full guide, see [Getting Started](getting-started.md).
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Trading Examples
|
|
2
|
+
|
|
3
|
+
## Limit order vs. market order
|
|
4
|
+
|
|
5
|
+
When you open or decrease a position, you choose how the order is executed:
|
|
6
|
+
|
|
7
|
+
| Type | `isLimitOrder` | `isIocOrder` | Behavior |
|
|
8
|
+
|------|----------------|--------------|----------|
|
|
9
|
+
| **Market order** | `false` | — | Execute immediately at market. Use **slippage** (`pricesSlippage`, `collateralSlippage`) to bound worst price. |
|
|
10
|
+
| **Limit order** | `true` | `false` | Stored as a pending order; executes when the price condition is met. Typically use **zero or small slippage** (`pricesSlippage: 0`). |
|
|
11
|
+
| **IOC limit order** | `true` | `true` | Fill only if the limit can be met immediately; otherwise cancel (no partial fill). |
|
|
12
|
+
|
|
13
|
+
- **Market**: best for “get in/out now”; you accept some slippage.
|
|
14
|
+
- **Limit**: best when you want a specific price; order stays pending until the price condition is met.
|
|
15
|
+
- **IOC limit**: “fill at my price or not at all” in one block.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## ZLP / SLP: Open position (market order)
|
|
20
|
+
|
|
21
|
+
Execute immediately with slippage protection:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
const tx = await zlpAPI.openPositionV2(
|
|
25
|
+
'usdc', // collateral token
|
|
26
|
+
'btc', // index token
|
|
27
|
+
BigInt(1000000), // size
|
|
28
|
+
BigInt(100000), // collateral amount
|
|
29
|
+
['coinObjectId'], // coin objects
|
|
30
|
+
true, // long position
|
|
31
|
+
BigInt(50000), // reserve amount
|
|
32
|
+
30000, // index price (reference)
|
|
33
|
+
1.5, // collateral price (reference)
|
|
34
|
+
false, // isLimitOrder: false = market order
|
|
35
|
+
false, // isIocOrder (ignored for market)
|
|
36
|
+
0.003, // pricesSlippage: 0.3% for market
|
|
37
|
+
0.5, // collateralSlippage: 50% for market
|
|
38
|
+
BigInt(500), // relayer fee
|
|
39
|
+
'referralAddress',
|
|
40
|
+
'senderAddress'
|
|
41
|
+
)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## ZLP / SLP: Open position (limit order)
|
|
47
|
+
|
|
48
|
+
Pending order at your limit price; use zero or small slippage:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
const tx = await zlpAPI.openPositionV2(
|
|
52
|
+
'usdc',
|
|
53
|
+
'btc',
|
|
54
|
+
BigInt(1000000),
|
|
55
|
+
BigInt(100000),
|
|
56
|
+
['coinObjectId'],
|
|
57
|
+
true, // long
|
|
58
|
+
BigInt(50000),
|
|
59
|
+
30000, // your limit price (index)
|
|
60
|
+
1.5, // collateral price
|
|
61
|
+
true, // isLimitOrder: true = limit order
|
|
62
|
+
false, // isIocOrder: false = pending until price is met
|
|
63
|
+
0, // pricesSlippage: 0 for limit (exact price)
|
|
64
|
+
0.5, // collateralSlippage
|
|
65
|
+
BigInt(500),
|
|
66
|
+
'referralAddress',
|
|
67
|
+
'senderAddress'
|
|
68
|
+
)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## ZLP / SLP: Open position (IOC limit order)
|
|
74
|
+
|
|
75
|
+
Fill only if the limit can be met immediately; otherwise the order does not execute:
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
const tx = await zlpAPI.openPositionV2(
|
|
79
|
+
'usdc',
|
|
80
|
+
'btc',
|
|
81
|
+
BigInt(1000000),
|
|
82
|
+
BigInt(100000),
|
|
83
|
+
['coinObjectId'],
|
|
84
|
+
true,
|
|
85
|
+
BigInt(50000),
|
|
86
|
+
30000,
|
|
87
|
+
1.5,
|
|
88
|
+
true, // isLimitOrder: true
|
|
89
|
+
true, // isIocOrder: true = fill now or cancel
|
|
90
|
+
0,
|
|
91
|
+
0.5,
|
|
92
|
+
BigInt(500),
|
|
93
|
+
'referralAddress',
|
|
94
|
+
'senderAddress'
|
|
95
|
+
)
|
|
96
|
+
```
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Type Safety
|
|
2
|
+
|
|
3
|
+
The SDK is built with TypeScript and provides comprehensive type definitions.
|
|
4
|
+
|
|
5
|
+
## Interfaces
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import type {
|
|
9
|
+
IBaseAPI,
|
|
10
|
+
IBaseDataAPI,
|
|
11
|
+
IZLPAPI,
|
|
12
|
+
ISLPAPI,
|
|
13
|
+
IUSDZAPI,
|
|
14
|
+
IBaseMarketValuationInfo,
|
|
15
|
+
IBaseVaultInfo,
|
|
16
|
+
IBaseSymbolInfo,
|
|
17
|
+
IBasePositionInfo,
|
|
18
|
+
IBaseOrderInfo
|
|
19
|
+
} from 'zo-sdk'
|
|
20
|
+
|
|
21
|
+
// All APIs implement their respective interfaces
|
|
22
|
+
const zlpAPI: IZLPAPI = SDK.createZLPAPI(network, provider, apiEndpoint, connectionURL)
|
|
23
|
+
const slpAPI: ISLPAPI = SDK.createSLPAPI(network, provider, apiEndpoint, connectionURL)
|
|
24
|
+
const usdzAPI: IUSDZAPI = SDK.createUSDZAPI(network, provider, apiEndpoint, connectionURL)
|
|
25
|
+
|
|
26
|
+
// Type-safe data: call data methods directly on the API or via .dataAPI
|
|
27
|
+
const marketInfo: IBaseMarketValuationInfo = await zlpAPI.valuateMarket()
|
|
28
|
+
const vaultInfo: IBaseVaultInfo = await zlpAPI.getVaultInfo('usdc')
|
|
29
|
+
```
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineConfig } from 'eslint-config-hyoban'
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
react: 'vite',
|
|
5
|
+
restrictedSyntax: ['jsx', 'tsx'],
|
|
6
|
+
strict: true,
|
|
7
|
+
}, {
|
|
8
|
+
rules: {
|
|
9
|
+
'react-hooks/rules-of-hooks': 'error',
|
|
10
|
+
'react-hooks/exhaustive-deps': 'error',
|
|
11
|
+
'react-refresh/only-export-components': 'off',
|
|
12
|
+
'max-params': 'off',
|
|
13
|
+
|
|
14
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
|
15
|
+
'unicorn/expiring-todo-comments': 'off',
|
|
16
|
+
'@eslint-react/jsx-no-undef': 'off',
|
|
17
|
+
},
|
|
18
|
+
})
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zofai/zo-sdk",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.92",
|
|
5
|
+
"author": "zo",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": {
|
|
9
|
+
"types": "./dist/index.d.mts",
|
|
10
|
+
"default": "./dist/index.mjs"
|
|
11
|
+
},
|
|
12
|
+
"require": {
|
|
13
|
+
"types": "./dist/index.d.cts",
|
|
14
|
+
"default": "./dist/index.cjs"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"main": "./dist/index.cjs",
|
|
19
|
+
"module": "./dist/index.mjs",
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@mysten/bcs": "^1.1.0",
|
|
23
|
+
"@mysten/kiosk": "^0.12.17",
|
|
24
|
+
"@mysten/sui": "^1.36.0",
|
|
25
|
+
"@pythnetwork/pyth-sui-js": "2.2.0",
|
|
26
|
+
"decimal.js": "10.4.3"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@ts-bridge/cli": "^0.6.3",
|
|
30
|
+
"eslint": "^9.32.0",
|
|
31
|
+
"eslint-config-hyoban": "^4.0.9",
|
|
32
|
+
"tsx": "^4.19.3",
|
|
33
|
+
"typescript": "^5.8.2"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "ts-bridge build --project ./tsconfig.json --clean",
|
|
37
|
+
"pub": "pnpm build && npm publish",
|
|
38
|
+
"serve": "tsx dist/index.js",
|
|
39
|
+
"start": "tsx src/index.ts",
|
|
40
|
+
"test": "vitest"
|
|
41
|
+
}
|
|
42
|
+
}
|