orbit-dlmm 0.1.0
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/LICENSE +21 -0
- package/README.md +167 -0
- package/dist/index.d.mts +645 -0
- package/dist/index.d.ts +645 -0
- package/dist/index.js +7084 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +7021 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 CipherLabs
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://img.shields.io/npm/v/@orbitfinance/dlmm?color=blue&label=npm" alt="npm" />
|
|
3
|
+
<img src="https://img.shields.io/badge/Solana-mainnet-9945FF?logo=solana" alt="Solana" />
|
|
4
|
+
<img src="https://img.shields.io/badge/license-MIT-green" alt="License" />
|
|
5
|
+
<img src="https://img.shields.io/badge/TypeScript-strict-blue?logo=typescript" alt="TypeScript" />
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
<h1 align="center">@orbitfinance/dlmm</h1>
|
|
9
|
+
<p align="center">TypeScript SDK for <a href="https://www.cipherlabsx.com">Orbit Finance DLMM</a> on Solana</p>
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## How it works
|
|
14
|
+
|
|
15
|
+
Orbit Finance uses a **bin-based concentrated liquidity** model. Liquidity is placed into discrete price bins, and swaps move through bins sequentially. This gives LPs precise control over their price range.
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
Price ($)
|
|
19
|
+
▲
|
|
20
|
+
│ ┌──┐
|
|
21
|
+
│ ┌──┤ │
|
|
22
|
+
│ ┌──┤ │ ├──┐
|
|
23
|
+
│ ┌──┤ │ │ │ ├──┐
|
|
24
|
+
│ │ │ │ │ │ │ │
|
|
25
|
+
└─┴──┴──┴──┴──┴──┴──┴──▶ Bins
|
|
26
|
+
-3 -2 -1 0 +1 +2 +3
|
|
27
|
+
▲
|
|
28
|
+
active bin
|
|
29
|
+
(current price)
|
|
30
|
+
|
|
31
|
+
◄── quote (USDC) ──►◄── base (CIPHER) ──►
|
|
32
|
+
bins below bins above
|
|
33
|
+
active bin active bin
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Bins below the active price hold quote tokens (USDC). Bins above hold base tokens (CIPHER). As price moves, bins get filled/emptied and LPs earn fees from every swap that crosses their range.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Install
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install @orbitfinance/dlmm @coral-xyz/anchor @solana/web3.js
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Quick start
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
50
|
+
import { CipherDlmm } from "@orbitfinance/dlmm";
|
|
51
|
+
|
|
52
|
+
const connection = new Connection("https://api.mainnet-beta.solana.com");
|
|
53
|
+
const pool = new PublicKey("EoLGqHKvtK9NcxjjnvSxTYYuFMYDeWTFFyKYj1DcJyPB");
|
|
54
|
+
|
|
55
|
+
// connect to a pool
|
|
56
|
+
const dlmm = await CipherDlmm.create(connection, pool);
|
|
57
|
+
console.log("active bin:", dlmm.getActiveBin());
|
|
58
|
+
|
|
59
|
+
// get positions
|
|
60
|
+
const positions = await dlmm.getPositionsByUser(myWallet);
|
|
61
|
+
|
|
62
|
+
// deposit liquidity (returns unsigned tx — you sign it)
|
|
63
|
+
const txs = await dlmm.addLiquidityByStrategy({
|
|
64
|
+
user: myWallet,
|
|
65
|
+
positionNonce: 0n,
|
|
66
|
+
totalBaseAmount: 1_000_000_000n, // 1 CIPHER
|
|
67
|
+
totalQuoteAmount: 5_000_000n, // 5 USDC
|
|
68
|
+
strategy: "concentrated",
|
|
69
|
+
minBinId: -1020,
|
|
70
|
+
maxBinId: -960,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// swap
|
|
74
|
+
const swapTx = await dlmm.swap({
|
|
75
|
+
user: myWallet,
|
|
76
|
+
amountIn: 1_000_000n, // 1 USDC
|
|
77
|
+
minAmountOut: 200_000_000n, // min 0.2 CIPHER
|
|
78
|
+
swapForBase: true,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// claim staking rewards
|
|
82
|
+
const claimTx = await dlmm.claimHolderRewards(myWallet);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
All write methods return **unsigned** `VersionedTransaction` objects. You handle signing however you want (Keypair, wallet adapter, multisig, whatever).
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## CipherDlmm class
|
|
90
|
+
|
|
91
|
+
| Method | Returns | What it does |
|
|
92
|
+
|--------|---------|--------------|
|
|
93
|
+
| `CipherDlmm.create(conn, pool)` | `CipherDlmm` | Connect to a pool |
|
|
94
|
+
| `.getActiveBin()` | `ActiveBin` | Current price bin |
|
|
95
|
+
| `.getBinArrays(min?, max?)` | `BinArrayState[]` | Bin liquidity data |
|
|
96
|
+
| `.getPositionsByUser(user)` | `UserPosition[]` | LP positions |
|
|
97
|
+
| `.addLiquidityByStrategy(params)` | `VersionedTransaction[]` | Deposit with auto-distribution |
|
|
98
|
+
| `.removeLiquidity(params)` | `VersionedTransaction` | Withdraw |
|
|
99
|
+
| `.swap(params)` | `VersionedTransaction` | Swap tokens |
|
|
100
|
+
| `.initializePosition(user, nonce)` | `VersionedTransaction` | Create new position |
|
|
101
|
+
| `.closePosition(user, pos)` | `VersionedTransaction` | Close empty position |
|
|
102
|
+
| `.claimHolderRewards(user)` | `VersionedTransaction` | Claim USDC rewards |
|
|
103
|
+
| `.initHolderState(user)` | `VersionedTransaction` | One-time init for rewards |
|
|
104
|
+
|
|
105
|
+
## Distribution strategies
|
|
106
|
+
|
|
107
|
+
Control how liquidity spreads across bins:
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
uniform concentrated skew_bid bid-ask
|
|
111
|
+
████████████ ▁▂▄█████▄▂▁ █████▄▃▂▁▁ ███▂▁▁▁▂███
|
|
112
|
+
(flat) (tight range) (buy-heavy) (edges only)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
| Strategy | Use case |
|
|
116
|
+
|----------|----------|
|
|
117
|
+
| `"uniform"` | Even spread, simple |
|
|
118
|
+
| `"concentrated"` | Tight range around current price, max fee capture |
|
|
119
|
+
| `"skew_bid"` | Bullish — more liquidity on the buy side |
|
|
120
|
+
| `"skew_ask"` | Bearish — more liquidity on the sell side |
|
|
121
|
+
| `"bid-ask"` | Market making — thick at edges, thin in the middle |
|
|
122
|
+
| `"curve"` | Wider bell curve, less concentrated |
|
|
123
|
+
|
|
124
|
+
## Low-level utilities
|
|
125
|
+
|
|
126
|
+
Don't need the class? Everything is also exported as standalone functions:
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
import {
|
|
130
|
+
// PDAs
|
|
131
|
+
derivePoolPda,
|
|
132
|
+
deriveBinArrayPda,
|
|
133
|
+
derivePositionPda,
|
|
134
|
+
|
|
135
|
+
// price math
|
|
136
|
+
calculatePriceQ64_64,
|
|
137
|
+
binIdToPrice,
|
|
138
|
+
priceToBinId,
|
|
139
|
+
|
|
140
|
+
// distribution
|
|
141
|
+
calculateDistributionWeights,
|
|
142
|
+
allocateToBins,
|
|
143
|
+
|
|
144
|
+
// fetching
|
|
145
|
+
fetchPool,
|
|
146
|
+
fetchBinArraysForRange,
|
|
147
|
+
|
|
148
|
+
// tx building
|
|
149
|
+
buildTransaction,
|
|
150
|
+
|
|
151
|
+
// errors
|
|
152
|
+
parseProgramError,
|
|
153
|
+
} from "@orbitfinance/dlmm";
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Program info
|
|
157
|
+
|
|
158
|
+
| | |
|
|
159
|
+
|---|---|
|
|
160
|
+
| **Program ID** | `Fn3fA3fjsmpULNL7E9U79jKTe1KHxPtQeWdURCbJXCnM` |
|
|
161
|
+
| **Network** | Solana mainnet |
|
|
162
|
+
| **Website** | [cipherlabsx.com](https://www.cipherlabsx.com) |
|
|
163
|
+
| **DEX** | [markets.cipherlabsx.com](https://markets.cipherlabsx.com) |
|
|
164
|
+
|
|
165
|
+
## License
|
|
166
|
+
|
|
167
|
+
MIT
|