@zofai/zo-sdk 0.2.29 → 0.2.30
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/dist/consts/deployments-zlp-mainnet.json +1 -1
- package/dist/consts/deployments-zo-oracle-mainnet.json +18 -1
- package/dist/implementations/ZLPAPI.cjs +456 -123
- package/dist/implementations/ZLPAPI.cjs.map +1 -1
- package/dist/implementations/ZLPAPI.d.cts +46 -1
- package/dist/implementations/ZLPAPI.d.cts.map +1 -1
- package/dist/implementations/ZLPAPI.d.mts +46 -1
- package/dist/implementations/ZLPAPI.d.mts.map +1 -1
- package/dist/implementations/ZLPAPI.mjs +457 -124
- package/dist/implementations/ZLPAPI.mjs.map +1 -1
- package/dist/implementations/ZLPDataAPI.cjs +38 -0
- package/dist/implementations/ZLPDataAPI.cjs.map +1 -1
- package/dist/implementations/ZLPDataAPI.d.cts +16 -0
- package/dist/implementations/ZLPDataAPI.d.cts.map +1 -1
- package/dist/implementations/ZLPDataAPI.d.mts +16 -0
- package/dist/implementations/ZLPDataAPI.d.mts.map +1 -1
- package/dist/implementations/ZLPDataAPI.mjs +38 -0
- package/dist/implementations/ZLPDataAPI.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/interfaces/zlp.d.cts +19 -0
- package/dist/interfaces/zlp.d.cts.map +1 -1
- package/dist/interfaces/zlp.d.mts +19 -0
- package/dist/interfaces/zlp.d.mts.map +1 -1
- package/docs/api-reference.md +45 -0
- package/docs/architecture.md +21 -3
- package/docs/common-operations.md +56 -8
- package/docs/getting-started.md +8 -3
- package/docs/lp-specific-features.md +89 -12
- package/docs/swap-integration.md +52 -20
- package/package.json +1 -1
- package/src/consts/deployments-zlp-mainnet.json +1 -1
- package/src/consts/deployments-zo-oracle-mainnet.json +18 -1
- package/src/implementations/ZLPAPI.ts +760 -151
- package/src/implementations/ZLPDataAPI.ts +42 -0
- package/src/index.ts +1 -0
- package/src/interfaces/zlp.ts +170 -0
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
These operations work across all LP tokens (ZLP, SLP, USDZ).
|
|
4
4
|
|
|
5
|
+
## Oracle model (Pyth Pro + Stork)
|
|
6
|
+
|
|
7
|
+
Newer market methods use **Pyth Pro** update bytes (verified on-chain) plus **Stork** where enabled, instead of per-token legacy Pyth feeder objects.
|
|
8
|
+
|
|
9
|
+
| Operation | How oracle updates are supplied |
|
|
10
|
+
|-----------|----------------------------------|
|
|
11
|
+
| **Deposit / withdraw** | Fetched automatically inside the SDK (`initValuationOracle`) |
|
|
12
|
+
| **Swap / open / decrease / redeem (v3+)** | Pass `pythProUpdateBytes` from `api.fetchPythProUpdateBytesForTokens(...)` |
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
// Tokens needed for a trade (collateral + index)
|
|
16
|
+
const pythProUpdateBytes = await zlpAPI.fetchPythProUpdateBytesForTokens(['nusdc', 'btc'])
|
|
17
|
+
|
|
18
|
+
// Tokens needed for a vault swap (all vaults are valued)
|
|
19
|
+
const swapUpdateBytes = await zlpAPI.fetchPythProUpdateBytesForTokens(
|
|
20
|
+
Object.keys(zlpAPI.consts.zoCore.vaults) // or sudoCore.vaults for SLP
|
|
21
|
+
)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Legacy `openPositionV2` / `swap` / `swapV2Ptb` paths still exist, but new integrations should use the Pyth Pro methods below.
|
|
25
|
+
|
|
5
26
|
## Data / read operations
|
|
6
27
|
|
|
7
28
|
Use the API or DataAPI; the methods are the same.
|
|
@@ -14,11 +35,15 @@ const positionCaps = await zlpAPI.getPositionCapInfoList(ownerAddress)
|
|
|
14
35
|
const positions = await zlpAPI.getPositionInfoList(positionCaps, ownerAddress)
|
|
15
36
|
```
|
|
16
37
|
|
|
38
|
+
`valuateMarket()` on SLP (and similar valuation helpers) resolves vault/symbol USD prices from Pyth Pro, including LST vaults as RR × SUI.
|
|
39
|
+
|
|
17
40
|
## Deposit
|
|
18
41
|
|
|
42
|
+
Deposit builds valuation on-chain with Pyth Pro automatically — no update bytes argument.
|
|
43
|
+
|
|
19
44
|
```typescript
|
|
20
45
|
const depositTx = await zlpAPI.deposit(
|
|
21
|
-
'
|
|
46
|
+
'nusdc', // coin type
|
|
22
47
|
['coinObjectId'], // coin object IDs
|
|
23
48
|
1000000, // amount
|
|
24
49
|
0, // minimum amount out (optional)
|
|
@@ -31,22 +56,45 @@ const usdzDepositTx = await usdzAPI.deposit('usdc', ['coinObjectId'], 1000000)
|
|
|
31
56
|
|
|
32
57
|
## Withdraw
|
|
33
58
|
|
|
59
|
+
Same as deposit: valuation oracle is initialized inside the SDK.
|
|
60
|
+
|
|
34
61
|
```typescript
|
|
35
62
|
const withdrawTx = await zlpAPI.withdraw(
|
|
36
|
-
'
|
|
63
|
+
'nusdc',
|
|
37
64
|
['lpCoinObjectId'],
|
|
38
65
|
1000000,
|
|
39
66
|
0
|
|
40
67
|
)
|
|
41
68
|
```
|
|
42
69
|
|
|
43
|
-
## Swap
|
|
70
|
+
## Swap (Pyth Pro)
|
|
71
|
+
|
|
72
|
+
Prefer the Pyth Pro swap methods:
|
|
73
|
+
|
|
74
|
+
| LP | Method | PTB (returns coin) |
|
|
75
|
+
|----|--------|--------------------|
|
|
76
|
+
| **ZLP / USDZ** | `swapV3` | `swapV3Ptb` |
|
|
77
|
+
| **SLP** | `swapV4` | `swapV4Ptb` |
|
|
44
78
|
|
|
45
79
|
```typescript
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
80
|
+
const vaultTokens = Object.keys(zlpAPI.consts.zoCore.vaults)
|
|
81
|
+
const pythProUpdateBytes = await zlpAPI.fetchPythProUpdateBytesForTokens(vaultTokens)
|
|
82
|
+
|
|
83
|
+
const swapTx = await zlpAPI.swapV3(
|
|
84
|
+
'nusdc', // from token
|
|
85
|
+
'sui', // to token
|
|
86
|
+
BigInt(1000000), // amount
|
|
87
|
+
['coinObjectId'], // coin objects
|
|
88
|
+
pythProUpdateBytes,
|
|
89
|
+
0 // minAmountOut (optional)
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
// SLP uses swapV4 with the same argument shape
|
|
93
|
+
const slpSwapTx = await slpAPI.swapV4(
|
|
94
|
+
'usdc',
|
|
95
|
+
'sui',
|
|
96
|
+
BigInt(1000000),
|
|
97
|
+
['coinObjectId'],
|
|
98
|
+
await slpAPI.fetchPythProUpdateBytesForTokens(Object.keys(slpAPI.consts.sudoCore.vaults)),
|
|
51
99
|
)
|
|
52
100
|
```
|
package/docs/getting-started.md
CHANGED
|
@@ -46,8 +46,11 @@ const zlpAPI = SDK.createZLPAPI(network, provider, apiEndpoint, connectionURL)
|
|
|
46
46
|
const marketData = await zlpAPI.valuateMarket()
|
|
47
47
|
const marketDataAlt = await zlpAPI.dataAPI.valuateMarket()
|
|
48
48
|
|
|
49
|
-
//
|
|
50
|
-
const depositTx = await zlpAPI.deposit('
|
|
49
|
+
// Deposit / withdraw fetch Pyth Pro valuation updates internally
|
|
50
|
+
const depositTx = await zlpAPI.deposit('nusdc', ['coinId'], 1000000)
|
|
51
|
+
|
|
52
|
+
// Trading / swap (v3+) need update bytes first
|
|
53
|
+
const pythProUpdateBytes = await zlpAPI.fetchPythProUpdateBytesForTokens(['nusdc', 'btc'])
|
|
51
54
|
```
|
|
52
55
|
|
|
53
56
|
**DataAPI** instances are for read-only usage when you don't need to build transactions:
|
|
@@ -55,6 +58,8 @@ const depositTx = await zlpAPI.deposit('usdc', ['coinId'], 1000000)
|
|
|
55
58
|
```typescript
|
|
56
59
|
const zlpDataAPI = SDK.createZLPDataAPI(network, provider, apiEndpoint, connectionURL)
|
|
57
60
|
const marketData = await zlpDataAPI.valuateMarket()
|
|
58
|
-
const vaultInfo = await zlpDataAPI.getVaultInfo('
|
|
61
|
+
const vaultInfo = await zlpDataAPI.getVaultInfo('nusdc')
|
|
59
62
|
// zlpDataAPI.deposit(...) does not exist
|
|
60
63
|
```
|
|
64
|
+
|
|
65
|
+
For Pyth Pro trading and swap examples, see [Common Operations](common-operations.md), [Trading Examples](lp-specific-features.md), and [Swap Integration](swap-integration.md).
|
|
@@ -14,15 +14,27 @@ When you open or decrease a position, you choose how the order is executed:
|
|
|
14
14
|
- **Limit**: best when you want a specific price; order stays pending until the price condition is met.
|
|
15
15
|
- **IOC limit**: “fill at my price or not at all” in one block.
|
|
16
16
|
|
|
17
|
+
## Pyth Pro trading methods
|
|
18
|
+
|
|
19
|
+
Use **`openPositionV3`** / **`decreasePositionV3`** (and SCard / coin variants) for ZLP, SLP, and USDZ. These take `pythProUpdateBytes` from `fetchPythProUpdateBytesForTokens`.
|
|
20
|
+
|
|
21
|
+
| Action | Method |
|
|
22
|
+
|--------|--------|
|
|
23
|
+
| Open | `openPositionV3`, `openPositionWithCoinV3`, `openPositionWithSCardV3`, `openPositionWithCoinAndSCardV3` |
|
|
24
|
+
| Decrease | `decreasePositionV3`, `decreasePositionWithSCardV3` |
|
|
25
|
+
| Redeem collateral | ZLP / USDZ: `redeemFromPositionV2` · SLP: `redeemFromPositionV3` |
|
|
26
|
+
|
|
17
27
|
---
|
|
18
28
|
|
|
19
|
-
##
|
|
29
|
+
## Open position (market order)
|
|
20
30
|
|
|
21
31
|
Execute immediately with slippage protection:
|
|
22
32
|
|
|
23
33
|
```typescript
|
|
24
|
-
const
|
|
25
|
-
|
|
34
|
+
const pythProUpdateBytes = await zlpAPI.fetchPythProUpdateBytesForTokens(['nusdc', 'btc'])
|
|
35
|
+
|
|
36
|
+
const tx = await zlpAPI.openPositionV3(
|
|
37
|
+
'nusdc', // collateral token
|
|
26
38
|
'btc', // index token
|
|
27
39
|
BigInt(1000000), // size
|
|
28
40
|
BigInt(100000), // collateral amount
|
|
@@ -30,7 +42,8 @@ const tx = await zlpAPI.openPositionV2(
|
|
|
30
42
|
true, // long position
|
|
31
43
|
BigInt(50000), // reserve amount
|
|
32
44
|
30000, // index price (reference)
|
|
33
|
-
1.
|
|
45
|
+
1.0, // collateral price (reference)
|
|
46
|
+
pythProUpdateBytes, // Pyth Pro update bytes
|
|
34
47
|
false, // isLimitOrder: false = market order
|
|
35
48
|
false, // isIocOrder (ignored for market)
|
|
36
49
|
0.003, // pricesSlippage: 0.3% for market
|
|
@@ -41,15 +54,19 @@ const tx = await zlpAPI.openPositionV2(
|
|
|
41
54
|
)
|
|
42
55
|
```
|
|
43
56
|
|
|
57
|
+
The same `openPositionV3` signature works on `slpAPI` and `usdzAPI`.
|
|
58
|
+
|
|
44
59
|
---
|
|
45
60
|
|
|
46
|
-
##
|
|
61
|
+
## Open position (limit order)
|
|
47
62
|
|
|
48
63
|
Pending order at your limit price; use zero or small slippage:
|
|
49
64
|
|
|
50
65
|
```typescript
|
|
51
|
-
const
|
|
52
|
-
|
|
66
|
+
const pythProUpdateBytes = await zlpAPI.fetchPythProUpdateBytesForTokens(['nusdc', 'btc'])
|
|
67
|
+
|
|
68
|
+
const tx = await zlpAPI.openPositionV3(
|
|
69
|
+
'nusdc',
|
|
53
70
|
'btc',
|
|
54
71
|
BigInt(1000000),
|
|
55
72
|
BigInt(100000),
|
|
@@ -57,7 +74,8 @@ const tx = await zlpAPI.openPositionV2(
|
|
|
57
74
|
true, // long
|
|
58
75
|
BigInt(50000),
|
|
59
76
|
30000, // your limit price (index)
|
|
60
|
-
1.
|
|
77
|
+
1.0, // collateral price
|
|
78
|
+
pythProUpdateBytes,
|
|
61
79
|
true, // isLimitOrder: true = limit order
|
|
62
80
|
false, // isIocOrder: false = pending until price is met
|
|
63
81
|
0, // pricesSlippage: 0 for limit (exact price)
|
|
@@ -70,13 +88,15 @@ const tx = await zlpAPI.openPositionV2(
|
|
|
70
88
|
|
|
71
89
|
---
|
|
72
90
|
|
|
73
|
-
##
|
|
91
|
+
## Open position (IOC limit order)
|
|
74
92
|
|
|
75
93
|
Fill only if the limit can be met immediately; otherwise the order does not execute:
|
|
76
94
|
|
|
77
95
|
```typescript
|
|
78
|
-
const
|
|
79
|
-
|
|
96
|
+
const pythProUpdateBytes = await zlpAPI.fetchPythProUpdateBytesForTokens(['nusdc', 'btc'])
|
|
97
|
+
|
|
98
|
+
const tx = await zlpAPI.openPositionV3(
|
|
99
|
+
'nusdc',
|
|
80
100
|
'btc',
|
|
81
101
|
BigInt(1000000),
|
|
82
102
|
BigInt(100000),
|
|
@@ -84,7 +104,8 @@ const tx = await zlpAPI.openPositionV2(
|
|
|
84
104
|
true,
|
|
85
105
|
BigInt(50000),
|
|
86
106
|
30000,
|
|
87
|
-
1.
|
|
107
|
+
1.0,
|
|
108
|
+
pythProUpdateBytes,
|
|
88
109
|
true, // isLimitOrder: true
|
|
89
110
|
true, // isIocOrder: true = fill now or cancel
|
|
90
111
|
0,
|
|
@@ -94,3 +115,59 @@ const tx = await zlpAPI.openPositionV2(
|
|
|
94
115
|
'senderAddress'
|
|
95
116
|
)
|
|
96
117
|
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Decrease position
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
const pythProUpdateBytes = await zlpAPI.fetchPythProUpdateBytesForTokens(['nusdc', 'btc'])
|
|
125
|
+
|
|
126
|
+
const tx = await zlpAPI.decreasePositionV3(
|
|
127
|
+
positionCapId,
|
|
128
|
+
'nusdc', // collateral token
|
|
129
|
+
'btc', // index token
|
|
130
|
+
BigInt(500000), // decrease amount
|
|
131
|
+
true, // long
|
|
132
|
+
30000, // index price
|
|
133
|
+
1.0, // collateral price
|
|
134
|
+
pythProUpdateBytes,
|
|
135
|
+
false, // isTriggerOrder
|
|
136
|
+
true, // isTakeProfitOrder
|
|
137
|
+
false, // isIocOrder
|
|
138
|
+
0.003, // pricesSlippage
|
|
139
|
+
0.5, // collateralSlippage
|
|
140
|
+
BigInt(500), // relayer fee
|
|
141
|
+
['coinObjectId'], // fee coin objects (or pass sender)
|
|
142
|
+
false, // sponsoredTx
|
|
143
|
+
'senderAddress'
|
|
144
|
+
)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Redeem collateral from a position
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
const pythProUpdateBytes = await zlpAPI.fetchPythProUpdateBytesForTokens(['nusdc', 'btc'])
|
|
153
|
+
|
|
154
|
+
// ZLP / USDZ
|
|
155
|
+
const redeemTx = await zlpAPI.redeemFromPositionV2(
|
|
156
|
+
positionCapId,
|
|
157
|
+
'nusdc',
|
|
158
|
+
'btc',
|
|
159
|
+
100000, // amount
|
|
160
|
+
true, // long
|
|
161
|
+
pythProUpdateBytes,
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
// SLP
|
|
165
|
+
const slpRedeemTx = await slpAPI.redeemFromPositionV3(
|
|
166
|
+
positionCapId,
|
|
167
|
+
'usdc',
|
|
168
|
+
'btc',
|
|
169
|
+
100000,
|
|
170
|
+
true,
|
|
171
|
+
pythProUpdateBytes,
|
|
172
|
+
)
|
|
173
|
+
```
|
package/docs/swap-integration.md
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
# Swap Integration
|
|
2
2
|
|
|
3
|
-
This guide covers how to integrate swaps using the ZO SDK. Swaps are supported on **ZLP**, **SLP**, and **USDZ
|
|
3
|
+
This guide covers how to integrate swaps using the ZO SDK. Swaps are supported on **ZLP**, **SLP**, and **USDZ**.
|
|
4
|
+
|
|
5
|
+
Prefer the **Pyth Pro** methods:
|
|
6
|
+
|
|
7
|
+
| LP | Swap (transfer output) | Swap PTB (return coin) |
|
|
8
|
+
|----|------------------------|-------------------------|
|
|
9
|
+
| **ZLP / USDZ** | `swapV3` | `swapV3Ptb` |
|
|
10
|
+
| **SLP** | `swapV4` | `swapV4Ptb` |
|
|
11
|
+
|
|
12
|
+
Fee estimation is available via `dataAPI.calculateSwapFeeBreakdown()`. Legacy `swap()` / `swapV2Ptb()` remain available but are not recommended for new integrations.
|
|
4
13
|
|
|
5
14
|
## Overview
|
|
6
15
|
|
|
7
16
|
A swap flow typically involves:
|
|
8
17
|
|
|
9
18
|
1. **Estimate fees** – Get the expected fee breakdown for the swap.
|
|
10
|
-
2. **
|
|
11
|
-
3. **
|
|
12
|
-
4. **
|
|
19
|
+
2. **Fetch Pyth Pro update bytes** – Required for vault valuation on the Pyth Pro path.
|
|
20
|
+
3. **Set slippage protection** – Compute `minAmountOut` based on expected output and slippage tolerance.
|
|
21
|
+
4. **Build transaction** – Call `swapV3` (ZLP/USDZ) or `swapV4` (SLP).
|
|
22
|
+
5. **Sign and send** – Sign with the wallet and submit to the network.
|
|
13
23
|
|
|
14
24
|
## Amounts and units
|
|
15
25
|
|
|
@@ -27,7 +37,7 @@ const fromAmount = BigInt(100 * 1e6) // 100_000_000 atomic units
|
|
|
27
37
|
Before building the swap transaction, you can estimate the fee breakdown to display to the user or compute a safe `minAmountOut`.
|
|
28
38
|
|
|
29
39
|
```typescript
|
|
30
|
-
import { SDK,
|
|
40
|
+
import { SDK, Network } from '@zofai/zo-sdk'
|
|
31
41
|
import { SuiClient } from '@mysten/sui/client'
|
|
32
42
|
|
|
33
43
|
const provider = new SuiClient({ url: 'https://fullnode.mainnet.sui.io' })
|
|
@@ -58,13 +68,14 @@ console.log(`Total fee: ${feeBreakdown.totalFeeValue.toFixed(4)} USD`)
|
|
|
58
68
|
console.log(`Fee rate: ${(feeBreakdown.totalFeeRate * 100).toFixed(2)}%`)
|
|
59
69
|
```
|
|
60
70
|
|
|
61
|
-
## Build and submit swap transaction
|
|
71
|
+
## Build and submit swap transaction (Pyth Pro)
|
|
62
72
|
|
|
63
|
-
|
|
73
|
+
You need:
|
|
64
74
|
|
|
65
75
|
- `fromToken`, `toToken` – token identifiers (e.g. `'usdc'`, `'sui'`).
|
|
66
76
|
- `fromAmount` – amount in atomic units (bigint).
|
|
67
77
|
- `fromCoinObjects` – owned coin object IDs for the source token.
|
|
78
|
+
- `pythProUpdateBytes` – from `fetchPythProUpdateBytesForTokens` over **all vault tokens** (swap values every vault).
|
|
68
79
|
- `minAmountOut` – optional; minimum output amount in atomic units (slippage protection).
|
|
69
80
|
|
|
70
81
|
```typescript
|
|
@@ -72,39 +83,48 @@ const slpAPI = SDK.createSLPAPI(network, provider, apiEndpoint, connectionURL)
|
|
|
72
83
|
|
|
73
84
|
const fromAmount = BigInt(100 * 1e6) // 100 USDC
|
|
74
85
|
const fromCoinObjects = ['0x...'] // user's USDC coin IDs
|
|
86
|
+
const minAmountOut = 0 // or compute from oracle + slippage
|
|
75
87
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const minAmountOut = 0 // or compute from oracle + slippage
|
|
88
|
+
const vaultTokens = Object.keys(slpAPI.consts.sudoCore.vaults)
|
|
89
|
+
const pythProUpdateBytes = await slpAPI.fetchPythProUpdateBytesForTokens(vaultTokens)
|
|
79
90
|
|
|
80
|
-
const tx = await slpAPI.
|
|
91
|
+
const tx = await slpAPI.swapV4(
|
|
81
92
|
'usdc',
|
|
82
93
|
'sui',
|
|
83
94
|
fromAmount,
|
|
84
95
|
fromCoinObjects,
|
|
96
|
+
pythProUpdateBytes,
|
|
85
97
|
minAmountOut
|
|
86
98
|
)
|
|
87
99
|
|
|
100
|
+
// ZLP / USDZ: use swapV3 with the same argument shape
|
|
101
|
+
// const tx = await zlpAPI.swapV3('nusdc', 'sui', fromAmount, fromCoinObjects, pythProUpdateBytes, minAmountOut)
|
|
102
|
+
|
|
88
103
|
// Sign with wallet and execute
|
|
89
104
|
// const signed = await signAndExecuteTransaction({ transaction: tx })
|
|
90
105
|
```
|
|
91
106
|
|
|
92
|
-
## Swap and return coin
|
|
107
|
+
## Swap and return coin (PTB)
|
|
93
108
|
|
|
94
|
-
Use `
|
|
109
|
+
Use `swapV3Ptb` (ZLP/USDZ) or `swapV4Ptb` (SLP) when you need the output coin as a `TransactionObjectArgument`—for example, to pass into another move call or transfer it in the same transaction.
|
|
95
110
|
|
|
96
111
|
Pass an optional `tx` to compose into an existing transaction; otherwise a new transaction is created (you must sign and execute it via your wallet).
|
|
97
112
|
|
|
98
113
|
```typescript
|
|
114
|
+
import { Transaction } from '@mysten/sui/transactions'
|
|
115
|
+
|
|
99
116
|
const slpAPI = SDK.createSLPAPI(network, provider, apiEndpoint, connectionURL)
|
|
117
|
+
const vaultTokens = Object.keys(slpAPI.consts.sudoCore.vaults)
|
|
118
|
+
const pythProUpdateBytes = await slpAPI.fetchPythProUpdateBytesForTokens(vaultTokens)
|
|
100
119
|
|
|
101
|
-
// Option 1: Standalone swap (tx created
|
|
120
|
+
// Option 1: Standalone swap (tx created / passed in)
|
|
102
121
|
const tx = new Transaction()
|
|
103
|
-
const outputCoin = await slpAPI.
|
|
122
|
+
const outputCoin = await slpAPI.swapV4Ptb(
|
|
104
123
|
'usdc',
|
|
105
124
|
'sui',
|
|
106
125
|
BigInt(100 * 1e6),
|
|
107
126
|
fromCoinObjects,
|
|
127
|
+
pythProUpdateBytes,
|
|
108
128
|
minAmountOut,
|
|
109
129
|
tx
|
|
110
130
|
)
|
|
@@ -112,14 +132,22 @@ const outputCoin = await slpAPI.swapV2Ptb(
|
|
|
112
132
|
|
|
113
133
|
// Option 2: Compose with other move calls
|
|
114
134
|
const composedTx = new Transaction()
|
|
115
|
-
const swapCoin = await slpAPI.
|
|
135
|
+
const swapCoin = await slpAPI.swapV4Ptb(
|
|
136
|
+
'usdc',
|
|
137
|
+
'sui',
|
|
138
|
+
BigInt(100 * 1e6),
|
|
139
|
+
fromCoinObjects,
|
|
140
|
+
pythProUpdateBytes,
|
|
141
|
+
minAmountOut,
|
|
142
|
+
composedTx
|
|
143
|
+
)
|
|
116
144
|
composedTx.transferObjects([swapCoin], composedTx.pure.address(recipientAddress))
|
|
117
145
|
```
|
|
118
146
|
|
|
119
147
|
## Complete integration example
|
|
120
148
|
|
|
121
149
|
```typescript
|
|
122
|
-
import { SDK,
|
|
150
|
+
import { SDK, Network } from '@zofai/zo-sdk'
|
|
123
151
|
import { SuiClient } from '@mysten/sui/client'
|
|
124
152
|
|
|
125
153
|
async function swapWithFeeEstimate(
|
|
@@ -151,12 +179,16 @@ async function swapWithFeeEstimate(
|
|
|
151
179
|
const expectedOutAtomic = (netValueUsd * (10 ** toDecimals)) / toPrice
|
|
152
180
|
const minAmountOut = Math.floor(expectedOutAtomic * (1 - slippageBps / 10000))
|
|
153
181
|
|
|
154
|
-
// 3.
|
|
155
|
-
const
|
|
182
|
+
// 3. Fetch Pyth Pro update for all vaults, then build transaction
|
|
183
|
+
const vaultTokens = Object.keys(api.consts.sudoCore.vaults)
|
|
184
|
+
const pythProUpdateBytes = await api.fetchPythProUpdateBytesForTokens(vaultTokens)
|
|
185
|
+
|
|
186
|
+
const tx = await api.swapV4(
|
|
156
187
|
fromToken,
|
|
157
188
|
toToken,
|
|
158
189
|
BigInt(fromAmountAtomic),
|
|
159
190
|
fromCoinObjects,
|
|
191
|
+
pythProUpdateBytes,
|
|
160
192
|
minAmountOut
|
|
161
193
|
)
|
|
162
194
|
|
|
@@ -180,4 +212,4 @@ Use `calculateSwapFeeBreakdown` to get the USD value of each component and the t
|
|
|
180
212
|
|
|
181
213
|
## Token identifiers
|
|
182
214
|
|
|
183
|
-
Tokens are identified by their symbol in the deployment config, e.g. `'sui'`, `'usdc'`, `'usdt'`, `'eth'`, `'btc'`. Ensure the `fromToken` and `toToken` values match those in the LP’s supported tokens.
|
|
215
|
+
Tokens are identified by their symbol in the deployment config, e.g. `'sui'`, `'usdc'`, `'nusdc'`, `'usdt'`, `'eth'`, `'btc'`. Ensure the `fromToken` and `toToken` values match those in the LP’s supported tokens.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"zo_core": {
|
|
3
3
|
"package": "0xf7fade57462e56e2eff1d7adef32e4fd285b21fd81f983f407bb7110ca766cda",
|
|
4
|
-
"upgraded_package": "
|
|
4
|
+
"upgraded_package": "0x79e9959dd864f2f073caf507228afaaccfb09276ced183dd15abcdf8375d4a88",
|
|
5
5
|
"upgrade_cap": "0xcc96f78abe0b868afaab05954ccc6357afb5d379a21389d6eb88dda8b1f60052",
|
|
6
6
|
"admin_cap": "0xbc10f6481f2b5d6185c73ee680aa90a60fe3854d9f638e00f7e00d3b6a88e2b8",
|
|
7
7
|
"market": "0x35c667bd8c401036103992791a924f31df0d104256a9e2313acee5b1bcf05b7e",
|
|
@@ -33,7 +33,24 @@
|
|
|
33
33
|
"eba0732395fae9dec4bae12e52760b35fc1c5671e2da8b449c9af4efe5d54341": 624,
|
|
34
34
|
"44465e17d2e9d390e70c999d5a11fda4f092847fcd2e3e5aa089d96c98a30e67": 172,
|
|
35
35
|
"925ca92ff005ae943c158e3563f59698ce7e75c5a8c8dd43303a0a154887b3e6": 657,
|
|
36
|
-
"8cead549d0e770dea8fdf5e018a85d59585265cf8bff16ba83962fc7996dbb7f": 2998
|
|
36
|
+
"8cead549d0e770dea8fdf5e018a85d59585265cf8bff16ba83962fc7996dbb7f": 2998,
|
|
37
|
+
"2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b": 8,
|
|
38
|
+
"2f95862b045670cd22bee3114c39763a4a08beeb663b145d283c31d7d1101c4f": 15,
|
|
39
|
+
"2a01deaec9e51a579277b34b122399984d0bbf57e2458a7e42fecd2829867a0d": 16,
|
|
40
|
+
"93da3352f9f1d105fdfe4971cfa80e9dd777bfc5d0f683ebb6e1294b92137bb7": 18,
|
|
41
|
+
"2b9ab1e972a281585084148ba1389800799bd4be63b957507db1349314e47445": 29,
|
|
42
|
+
"0a0408d619e9380abad35060f9192039ed5042fa6f82301d0e48bb52be830996": 92,
|
|
43
|
+
"4279e31cc369bbcc2faf022b382b080e32a8e689ff20fbc530d2a603eb6cd98b": 110,
|
|
44
|
+
"273717b49430906f4b0c230e99aa1007f83758e3199edbc887c0d06c3e332494": 163,
|
|
45
|
+
"58cd29ef0e714c5affc44f269b2c1899a52da4169d7acc147b9da692e6953608": 182,
|
|
46
|
+
"d40472610abe56d36d065a0cf889fc8f1dd9f3b7f2a478231a5fc6df07ea5ce3": 201,
|
|
47
|
+
"e67d98cc1fbd94f569d5ba6c3c3c759eb3ffc5d2b28e64538a53ae13efad8fd1": 648,
|
|
48
|
+
"2b529621fa6e2c8429f623ba705572aa64175d7768365ef829df6a12c9f365f4": 1818,
|
|
49
|
+
"8414cfadf82f6bed644d2e399c11df21ec0131aa574c56030b132113dbbf3a0a": 1841,
|
|
50
|
+
"d41369178d64f41d51ca95465c144a2c74d2fff30be69164835911943fa64c3e": 1854,
|
|
51
|
+
"a903b5a82cb572397e3d47595d2889cf80513f5b4cf7a36b513ae10cc8b1e338": 2310,
|
|
52
|
+
"fa9e8d4591613476ad0961732475dc08969d248faca270cc6c47efe009ea3070": 2311,
|
|
53
|
+
"1fc9127232d059b415f7b11989d06aa11a3563619e5b7a8e44ae440f0b95e4e1": 2700
|
|
37
54
|
}
|
|
38
55
|
},
|
|
39
56
|
"stork_feeder": {
|