@epicentral/sos-sdk 0.1.0 → 0.1.1
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/.env.example +1 -0
- package/README.md +69 -131
- package/package.json +7 -4
package/.env.example
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
NPM_TOKEN=EnterNpmTokenHere
|
package/README.md
CHANGED
|
@@ -1,54 +1,50 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @epicentral/sos-sdk
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Solana Option Standard SDK. A frontend-first SDK for native options trading on Solana, built by Epicentral Labs.
|
|
4
|
+
|
|
5
|
+
Uses `@solana/kit` types (`Address`, `Instruction`, `Rpc`) across the public API.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
pnpm add @solana/kit decimal.js
|
|
10
|
+
pnpm add @epicentral/sos-sdk @solana/kit decimal.js
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
`@epicentral/sos-sdk`.
|
|
15
|
-
|
|
16
|
-
## Structure
|
|
17
|
-
|
|
18
|
-
- `client/` shared program constants and address helpers for the option program.
|
|
19
|
-
- `accounts/` PDA derivation and account fetch helpers.
|
|
20
|
-
- `long/` LONG buy/close/exercise/quote builders.
|
|
21
|
-
- `short/` SHORT mint/unwind/sync/settle plus premium/pool/loan builders.
|
|
22
|
-
- `omlp/` lender deposit/withdraw instruction builders.
|
|
23
|
-
- `shared/` common amount, error, and remaining account helpers.
|
|
24
|
-
- `generated/` Codama-generated client (bundled; do not edit).
|
|
13
|
+
## Overview
|
|
25
14
|
|
|
26
|
-
|
|
15
|
+
- **LONG** — Buy from pool, close to pool, exercise options.
|
|
16
|
+
- **SHORT** — Mint options, unwind, sync, settle, claim premium, close option.
|
|
17
|
+
- **Pool** — Deposit, withdraw, borrow, repay liquidity.
|
|
18
|
+
- **OMLP** — Lender deposit and withdraw.
|
|
19
|
+
- **Accounts** — PDA derivation and account fetchers for options, pools, vaults.
|
|
27
20
|
|
|
28
|
-
|
|
21
|
+
Each flow exposes `build*Instruction` for single instruction composition and `build*Transaction` for full-flow `Instruction[]` construction.
|
|
29
22
|
|
|
30
|
-
|
|
31
|
-
2. Sync into the SDK and copy to the standalone repo: `yarn sync:sdk`.
|
|
23
|
+
## Usage
|
|
32
24
|
|
|
33
|
-
|
|
25
|
+
### Build + send (recommended)
|
|
34
26
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
- `build*Transaction(params)` for one-flow `Instruction[]` construction.
|
|
41
|
-
- optional domain services for multi-step flows (no send/confirm).
|
|
27
|
+
```ts
|
|
28
|
+
import {
|
|
29
|
+
buildBuyFromPoolTransaction,
|
|
30
|
+
sendBuiltTransaction,
|
|
31
|
+
} from "@epicentral/sos-sdk";
|
|
42
32
|
|
|
43
|
-
|
|
33
|
+
const built = await buildBuyFromPoolTransaction(params);
|
|
34
|
+
const signature = await sendBuiltTransaction({
|
|
35
|
+
rpc,
|
|
36
|
+
rpcSubscriptions,
|
|
37
|
+
feePayer: walletSigner,
|
|
38
|
+
instructions: built.instructions,
|
|
39
|
+
});
|
|
40
|
+
```
|
|
44
41
|
|
|
45
|
-
### Build + send (
|
|
42
|
+
### Build + send (manual)
|
|
46
43
|
|
|
47
44
|
```ts
|
|
48
45
|
import {
|
|
49
46
|
appendTransactionMessageInstructions,
|
|
50
47
|
createTransactionMessage,
|
|
51
|
-
getSignatureFromTransaction,
|
|
52
48
|
pipe,
|
|
53
49
|
sendAndConfirmTransactionFactory,
|
|
54
50
|
setTransactionMessageFeePayerSigner,
|
|
@@ -71,64 +67,41 @@ const signedTx = await signTransactionMessageWithSigners(txMessage);
|
|
|
71
67
|
await sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions })(signedTx, {
|
|
72
68
|
commitment: "confirmed",
|
|
73
69
|
});
|
|
74
|
-
|
|
75
|
-
const signature = getSignatureFromTransaction(signedTx);
|
|
76
70
|
```
|
|
77
71
|
|
|
78
|
-
###
|
|
79
|
-
|
|
80
|
-
```ts
|
|
81
|
-
import {
|
|
82
|
-
buildBuyFromPoolTransaction,
|
|
83
|
-
sendBuiltTransaction,
|
|
84
|
-
} from "@epicentral/sos-sdk";
|
|
85
|
-
|
|
86
|
-
const built = await buildBuyFromPoolTransaction(params);
|
|
87
|
-
const signature = await sendBuiltTransaction({
|
|
88
|
-
rpc,
|
|
89
|
-
rpcSubscriptions,
|
|
90
|
-
feePayer: walletSigner,
|
|
91
|
-
instructions: built.instructions,
|
|
92
|
-
});
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### Open LONG / close LONG
|
|
72
|
+
### LONG
|
|
96
73
|
|
|
97
74
|
```ts
|
|
98
75
|
import {
|
|
99
76
|
buildBuyFromPoolTransaction,
|
|
100
77
|
buildCloseLongToPoolTransaction,
|
|
78
|
+
buildOptionExerciseTransaction,
|
|
101
79
|
} from "@epicentral/sos-sdk";
|
|
102
80
|
|
|
81
|
+
// Open LONG
|
|
103
82
|
const openLong = await buildBuyFromPoolTransaction(openLongParams);
|
|
104
|
-
const closeLong = await buildCloseLongToPoolTransaction(closeLongParams);
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
### Exercise LONG
|
|
108
83
|
|
|
109
|
-
|
|
110
|
-
|
|
84
|
+
// Close LONG
|
|
85
|
+
const closeLong = await buildCloseLongToPoolTransaction(closeLongParams);
|
|
111
86
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
positionAccount,
|
|
115
|
-
marketData,
|
|
116
|
-
underlyingMint,
|
|
117
|
-
priceUpdate,
|
|
118
|
-
buyerPaymentAccount,
|
|
119
|
-
makerCollateralAccount,
|
|
120
|
-
escrowState,
|
|
121
|
-
escrowTokenAccount,
|
|
122
|
-
escrowAuthority,
|
|
123
|
-
buyer,
|
|
124
|
-
});
|
|
87
|
+
// Exercise LONG
|
|
88
|
+
const exercise = buildOptionExerciseTransaction({ optionAccount, positionAccount, /* ... */ });
|
|
125
89
|
```
|
|
126
90
|
|
|
127
|
-
###
|
|
91
|
+
### SHORT
|
|
128
92
|
|
|
129
93
|
```ts
|
|
130
|
-
import {
|
|
94
|
+
import {
|
|
95
|
+
buildOptionMintTransaction,
|
|
96
|
+
buildUnwindWriterUnsoldTransaction,
|
|
97
|
+
buildSyncWriterPositionTransaction,
|
|
98
|
+
buildSettleMakerCollateralTransaction,
|
|
99
|
+
buildClaimPremiumTransaction,
|
|
100
|
+
buildCloseOptionTransaction,
|
|
101
|
+
} from "@epicentral/sos-sdk";
|
|
102
|
+
import { OptionType } from "@epicentral/sos-sdk";
|
|
131
103
|
|
|
104
|
+
// Mint (open SHORT)
|
|
132
105
|
const built = await buildOptionMintTransaction({
|
|
133
106
|
optionType: OptionType.Call,
|
|
134
107
|
strikePrice,
|
|
@@ -142,53 +115,25 @@ const built = await buildOptionMintTransaction({
|
|
|
142
115
|
makerCollateralAccount,
|
|
143
116
|
underlyingMint,
|
|
144
117
|
});
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
### Unwind / Sync / Settle SHORT
|
|
148
|
-
|
|
149
|
-
```ts
|
|
150
|
-
import {
|
|
151
|
-
buildSettleMakerCollateralTransaction,
|
|
152
|
-
buildSyncWriterPositionTransaction,
|
|
153
|
-
buildUnwindWriterUnsoldTransaction,
|
|
154
|
-
} from "@epicentral/sos-sdk";
|
|
155
118
|
|
|
119
|
+
// Unwind / Sync / Settle
|
|
156
120
|
const unwind = await buildUnwindWriterUnsoldTransaction(unwindParams);
|
|
157
121
|
const sync = buildSyncWriterPositionTransaction(syncParams);
|
|
158
122
|
const settle = await buildSettleMakerCollateralTransaction(settleParams);
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### Claim premium / close option
|
|
162
|
-
|
|
163
|
-
```ts
|
|
164
|
-
import {
|
|
165
|
-
buildClaimPremiumTransaction,
|
|
166
|
-
buildCloseOptionTransaction,
|
|
167
|
-
} from "@epicentral/sos-sdk";
|
|
168
|
-
|
|
169
|
-
const claim = await buildClaimPremiumTransaction({
|
|
170
|
-
optionPool,
|
|
171
|
-
makerPaymentAccount,
|
|
172
|
-
premiumVault,
|
|
173
|
-
maker,
|
|
174
|
-
});
|
|
175
123
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
makerOptionAccount,
|
|
180
|
-
maker,
|
|
181
|
-
});
|
|
124
|
+
// Claim premium / close option
|
|
125
|
+
const claim = await buildClaimPremiumTransaction({ optionPool, makerPaymentAccount, premiumVault, maker });
|
|
126
|
+
const close = buildCloseOptionTransaction({ optionAccount, optionMint, makerOptionAccount, maker });
|
|
182
127
|
```
|
|
183
128
|
|
|
184
|
-
### Pool
|
|
129
|
+
### Pool
|
|
185
130
|
|
|
186
131
|
```ts
|
|
187
132
|
import {
|
|
188
|
-
buildBorrowFromPoolTransaction,
|
|
189
133
|
buildDepositToPoolTransaction,
|
|
190
|
-
buildRepayPoolLoanTransaction,
|
|
191
134
|
buildWithdrawFromPoolTransaction,
|
|
135
|
+
buildBorrowFromPoolTransaction,
|
|
136
|
+
buildRepayPoolLoanTransaction,
|
|
192
137
|
} from "@epicentral/sos-sdk";
|
|
193
138
|
|
|
194
139
|
const deposit = await buildDepositToPoolTransaction(depositToPoolParams);
|
|
@@ -197,12 +142,7 @@ const borrow = await buildBorrowFromPoolTransaction(borrowFromPoolParams);
|
|
|
197
142
|
const repay = await buildRepayPoolLoanTransaction(repayPoolLoanParams);
|
|
198
143
|
```
|
|
199
144
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
- `buildRepayPoolLoanTransaction`: principal is repaid from `escrowTokenAccount`; accrued interest + protocol fees are repaid from `makerTokenAccount`.
|
|
203
|
-
- `buildRepayPoolLoanFromCollateralTransaction`: full repayment is sourced from `collateralVault`.
|
|
204
|
-
|
|
205
|
-
### OMLP deposit/withdraw
|
|
145
|
+
### OMLP
|
|
206
146
|
|
|
207
147
|
```ts
|
|
208
148
|
import {
|
|
@@ -210,16 +150,23 @@ import {
|
|
|
210
150
|
buildWithdrawFromPositionTransaction,
|
|
211
151
|
} from "@epicentral/sos-sdk";
|
|
212
152
|
|
|
213
|
-
const deposit = await buildDepositToPositionTransaction(
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
);
|
|
153
|
+
const deposit = await buildDepositToPositionTransaction({
|
|
154
|
+
vault,
|
|
155
|
+
lenderTokenAccount,
|
|
156
|
+
vaultTokenAccount,
|
|
157
|
+
lender,
|
|
158
|
+
amount,
|
|
159
|
+
});
|
|
160
|
+
const withdraw = await buildWithdrawFromPositionTransaction({
|
|
161
|
+
vault,
|
|
162
|
+
vaultTokenAccount,
|
|
163
|
+
lenderTokenAccount,
|
|
164
|
+
lender,
|
|
165
|
+
amount,
|
|
166
|
+
});
|
|
220
167
|
```
|
|
221
168
|
|
|
222
|
-
###
|
|
169
|
+
### Fetch accounts
|
|
223
170
|
|
|
224
171
|
```ts
|
|
225
172
|
import { fetchOptionAccount, fetchOptionPool, fetchVault } from "@epicentral/sos-sdk";
|
|
@@ -228,12 +175,3 @@ const option = await fetchOptionAccount(rpc, optionAddress);
|
|
|
228
175
|
const pool = await fetchOptionPool(rpc, optionPoolAddress);
|
|
229
176
|
const vault = await fetchVault(rpc, vaultAddress);
|
|
230
177
|
```
|
|
231
|
-
|
|
232
|
-
## Migration notes
|
|
233
|
-
|
|
234
|
-
- This SDK is the only frontend integration surface for this repository.
|
|
235
|
-
- Legacy `frontend/constants`, `frontend/services`, and `frontend/utils` modules were removed.
|
|
236
|
-
- Replace Anchor `program.account.*` reads with SDK fetchers.
|
|
237
|
-
- Replace Anchor `program.methods.*` writes with SDK builders.
|
|
238
|
-
- App code should own message building, signing, send, and confirmation via `@solana/kit`.
|
|
239
|
-
- `long/service.ts` and `short/service.ts` were removed in favor of direct builder calls.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@epicentral/sos-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Solana Option Standard SDK. The frontend-first SDK for Native Options Trading on Solana. Created by Epicentral Labs.",
|
|
6
6
|
"type": "module",
|
|
@@ -11,12 +11,15 @@
|
|
|
11
11
|
".": "./index.ts",
|
|
12
12
|
"./*": "./*"
|
|
13
13
|
},
|
|
14
|
-
"
|
|
15
|
-
"
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"dotenv-cli": "^8.0.0"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@solana/kit": "^6.1.0",
|
|
19
19
|
"bs58": "^6.0.0",
|
|
20
20
|
"decimal.js": "^10.4.3"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"typecheck": "tsc --project tsconfig.json --noEmit"
|
|
21
24
|
}
|
|
22
|
-
}
|
|
25
|
+
}
|