@cubee_ee/sdk 0.1.8 → 0.2.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/README.md +50 -0
- package/dist/clients/CubicPoolClient.d.ts.map +1 -1
- package/dist/clients/CubicPoolClient.js +1 -0
- package/dist/clients/CubicPoolClient.js.map +1 -1
- package/dist/clients/index.d.ts +1 -0
- package/dist/clients/index.d.ts.map +1 -1
- package/dist/clients/index.js +1 -0
- package/dist/clients/index.js.map +1 -1
- package/dist/clients/tx-builders.d.ts +44 -0
- package/dist/clients/tx-builders.d.ts.map +1 -1
- package/dist/clients/tx-builders.js +59 -0
- package/dist/clients/tx-builders.js.map +1 -1
- package/dist/clients/versioned.d.ts +34 -0
- package/dist/clients/versioned.d.ts.map +1 -0
- package/dist/clients/versioned.js +55 -0
- package/dist/clients/versioned.js.map +1 -0
- package/dist/idl/cubic_pool.json +1101 -114
- package/dist/idl/index.d.ts +380 -16
- package/dist/idl/index.d.ts.map +1 -1
- package/dist/idl/protocol_admin.json +513 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/parsers/poolAccount.d.ts +42 -11
- package/dist/parsers/poolAccount.d.ts.map +1 -1
- package/dist/parsers/poolAccount.js +96 -37
- package/dist/parsers/poolAccount.js.map +1 -1
- package/dist/types/pool.d.ts +6 -0
- package/dist/types/pool.d.ts.map +1 -1
- package/dist/types/result.d.ts +1 -1
- package/dist/types/result.d.ts.map +1 -1
- package/dist/types/result.js.map +1 -1
- package/package.json +1 -1
- package/src/clients/CubicPoolClient.ts +1 -0
- package/src/clients/index.ts +1 -0
- package/src/clients/tx-builders.ts +100 -0
- package/src/clients/versioned.ts +80 -0
- package/src/idl/cubic_pool.json +1101 -114
- package/src/idl/protocol_admin.json +513 -2
- package/src/index.ts +5 -0
- package/src/parsers/poolAccount.ts +151 -48
- package/src/types/pool.ts +6 -0
- package/src/types/result.ts +1 -0
|
@@ -2,43 +2,89 @@ import { PublicKey } from "@solana/web3.js";
|
|
|
2
2
|
import BN from "bn.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Raw binary layout of CubicPool (see
|
|
6
|
-
* `contracts/programs/cubic-pool/src/state/cubic_pool.rs`).
|
|
5
|
+
* Raw binary layout of CubicPool **v4** (see
|
|
6
|
+
* `contracts/programs/cubic-pool/src/state/cubic_pool.rs`).
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* v4 reorganised per-token data from six parallel arrays into a single
|
|
9
|
+
* `tokens: [TokenSlot; 10]` array (each slot = `AssetConfig` +
|
|
10
|
+
* `AssetDynamics`). For backwards compatibility with downstream
|
|
11
|
+
* consumers (`CubicPoolClient.sync()` and similar), this decoder still
|
|
12
|
+
* exposes the parallel-array shape, plus the new max-selloff and admin
|
|
13
|
+
* fields.
|
|
14
|
+
*
|
|
15
|
+
* We decode manually to avoid bundling an Anchor `Program` instance into
|
|
16
|
+
* the SDK — both frontend and backend consume the SDK, and pulling the
|
|
17
|
+
* full Anchor runtime is heavy. The on-chain layout is stable (trailing
|
|
18
|
+
* `reserved[64]` blob keeps room for forward extensions).
|
|
12
19
|
*/
|
|
13
20
|
export interface RawPoolAccount {
|
|
14
21
|
config: PublicKey;
|
|
15
22
|
bump: number;
|
|
16
23
|
tokenCount: number;
|
|
17
24
|
poolId: BN;
|
|
18
|
-
tokenMints: PublicKey[]; // length 10
|
|
19
|
-
tokenPrograms: PublicKey[]; // length 10
|
|
20
|
-
normalizedWeights: BN[]; // length 10
|
|
21
|
-
virtualBalances: BN[]; // length 10
|
|
22
|
-
actualBalances: BN[]; // length 10
|
|
23
25
|
swapFeeRate: number;
|
|
24
26
|
protocolFeeRate: number;
|
|
25
|
-
protocolFeesOwed: BN[]; // length 10
|
|
26
27
|
createdAt: BN;
|
|
27
28
|
poolEnabled: boolean;
|
|
28
29
|
swapsEnabled: boolean;
|
|
30
|
+
poolAdmin: PublicKey;
|
|
31
|
+
pendingPoolAdmin: PublicKey;
|
|
32
|
+
|
|
33
|
+
rangeManager: PublicKey;
|
|
34
|
+
rangeManagerEnabled: boolean;
|
|
35
|
+
rangeManagerMaxVbChangeBps: number;
|
|
36
|
+
rangeManagerMaxWeightChangeBps: number;
|
|
37
|
+
rangeManagerMinUpdateIntervalSecs: number;
|
|
38
|
+
rangeManagerLastUpdated: BN;
|
|
39
|
+
|
|
40
|
+
// Per-token (length 10 each; values past `tokenCount` are zeroed).
|
|
41
|
+
tokenMints: PublicKey[];
|
|
42
|
+
tokenPrograms: PublicKey[];
|
|
43
|
+
normalizedWeights: BN[];
|
|
44
|
+
maxSelloff: BN[];
|
|
45
|
+
maxSelloffPeriodLength: number[];
|
|
46
|
+
|
|
47
|
+
virtualBalances: BN[];
|
|
48
|
+
actualBalances: BN[];
|
|
49
|
+
protocolFeesOwed: BN[];
|
|
50
|
+
previousSelloff: BN[];
|
|
51
|
+
currentSelloff: BN[];
|
|
52
|
+
windowStartTimestamp: BN[];
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Per-pool Address Lookup Table. `PublicKey.default` means the pool's
|
|
56
|
+
* ALT has not been provisioned yet (`initialize_pool_alt` not called).
|
|
57
|
+
* SDK uses this to choose between v0 (with ALT) and legacy tx-building
|
|
58
|
+
* paths.
|
|
59
|
+
*/
|
|
60
|
+
lookupTable: PublicKey;
|
|
29
61
|
}
|
|
30
62
|
|
|
31
63
|
/** 8-byte anchor discriminator for CubicPool. */
|
|
32
64
|
export const POOL_DISCRIMINATOR_LEN = 8;
|
|
33
65
|
const MAX_TOKENS = 10;
|
|
66
|
+
/** Total on-chain size of a v4 CubicPool (includes the 8-byte discriminator). */
|
|
67
|
+
export const POOL_V4_LEN = 1683;
|
|
68
|
+
/** Pre-v4 size — accounts at this size still need `migrate_pool_v4`. */
|
|
69
|
+
export const POOL_V3_LEN = 1154;
|
|
34
70
|
|
|
35
71
|
export function decodePoolAccount(data: Buffer): RawPoolAccount {
|
|
36
|
-
if (data.length
|
|
37
|
-
throw new Error(
|
|
72
|
+
if (data.length === POOL_V3_LEN) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
`decodePoolAccount: account is at v3 size (${POOL_V3_LEN}). ` +
|
|
75
|
+
`Run migrate_pool_v4 against it before calling this decoder.`,
|
|
76
|
+
);
|
|
38
77
|
}
|
|
78
|
+
if (data.length !== POOL_V4_LEN) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`decodePoolAccount: unexpected data length ${data.length} ` +
|
|
81
|
+
`(expected ${POOL_V4_LEN} for v4).`,
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
39
85
|
let off = POOL_DISCRIMINATOR_LEN;
|
|
40
86
|
|
|
41
|
-
const config =
|
|
87
|
+
const config = readPubkey(data, off);
|
|
42
88
|
off += 32;
|
|
43
89
|
const bump = data.readUInt8(off);
|
|
44
90
|
off += 1;
|
|
@@ -46,68 +92,125 @@ export function decodePoolAccount(data: Buffer): RawPoolAccount {
|
|
|
46
92
|
off += 1;
|
|
47
93
|
const poolId = readU64LE(data, off);
|
|
48
94
|
off += 8;
|
|
95
|
+
const swapFeeRate = data.readUInt32LE(off);
|
|
96
|
+
off += 4;
|
|
97
|
+
const protocolFeeRate = data.readUInt16LE(off);
|
|
98
|
+
off += 2;
|
|
99
|
+
const createdAt = readI64LE(data, off);
|
|
100
|
+
off += 8;
|
|
101
|
+
const poolEnabled = data.readUInt8(off) !== 0;
|
|
102
|
+
off += 1;
|
|
103
|
+
const swapsEnabled = data.readUInt8(off) !== 0;
|
|
104
|
+
off += 1;
|
|
105
|
+
const poolAdmin = readPubkey(data, off);
|
|
106
|
+
off += 32;
|
|
107
|
+
const pendingPoolAdmin = readPubkey(data, off);
|
|
108
|
+
off += 32;
|
|
49
109
|
|
|
110
|
+
const rangeManager = readPubkey(data, off);
|
|
111
|
+
off += 32;
|
|
112
|
+
const rangeManagerEnabled = data.readUInt8(off) !== 0;
|
|
113
|
+
off += 1;
|
|
114
|
+
const rangeManagerMaxVbChangeBps = data.readUInt16LE(off);
|
|
115
|
+
off += 2;
|
|
116
|
+
const rangeManagerMaxWeightChangeBps = data.readUInt16LE(off);
|
|
117
|
+
off += 2;
|
|
118
|
+
const rangeManagerMinUpdateIntervalSecs = data.readUInt32LE(off);
|
|
119
|
+
off += 4;
|
|
120
|
+
const rangeManagerLastUpdated = readI64LE(data, off);
|
|
121
|
+
off += 8;
|
|
122
|
+
|
|
123
|
+
// Per-token AoS — 10 slots, each 144 bytes.
|
|
50
124
|
const tokenMints: PublicKey[] = [];
|
|
51
|
-
for (let i = 0; i < MAX_TOKENS; i++) {
|
|
52
|
-
tokenMints.push(new PublicKey(data.slice(off, off + 32)));
|
|
53
|
-
off += 32;
|
|
54
|
-
}
|
|
55
125
|
const tokenPrograms: PublicKey[] = [];
|
|
56
|
-
for (let i = 0; i < MAX_TOKENS; i++) {
|
|
57
|
-
tokenPrograms.push(new PublicKey(data.slice(off, off + 32)));
|
|
58
|
-
off += 32;
|
|
59
|
-
}
|
|
60
126
|
const normalizedWeights: BN[] = [];
|
|
127
|
+
const maxSelloff: BN[] = [];
|
|
128
|
+
const maxSelloffPeriodLength: number[] = [];
|
|
129
|
+
const virtualBalances: BN[] = [];
|
|
130
|
+
const actualBalances: BN[] = [];
|
|
131
|
+
const protocolFeesOwed: BN[] = [];
|
|
132
|
+
const previousSelloff: BN[] = [];
|
|
133
|
+
const currentSelloff: BN[] = [];
|
|
134
|
+
const windowStartTimestamp: BN[] = [];
|
|
135
|
+
|
|
61
136
|
for (let i = 0; i < MAX_TOKENS; i++) {
|
|
137
|
+
// AssetConfig — 88 bytes
|
|
138
|
+
tokenMints.push(readPubkey(data, off));
|
|
139
|
+
off += 32;
|
|
140
|
+
tokenPrograms.push(readPubkey(data, off));
|
|
141
|
+
off += 32;
|
|
62
142
|
normalizedWeights.push(readU64LE(data, off));
|
|
63
143
|
off += 8;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
144
|
+
maxSelloff.push(readU64LE(data, off));
|
|
145
|
+
off += 8;
|
|
146
|
+
maxSelloffPeriodLength.push(data.readUInt32LE(off));
|
|
147
|
+
off += 4;
|
|
148
|
+
off += 4; // AssetConfig.reserved
|
|
149
|
+
|
|
150
|
+
// AssetDynamics — 56 bytes
|
|
67
151
|
virtualBalances.push(readU64LE(data, off));
|
|
68
152
|
off += 8;
|
|
69
|
-
}
|
|
70
|
-
const actualBalances: BN[] = [];
|
|
71
|
-
for (let i = 0; i < MAX_TOKENS; i++) {
|
|
72
153
|
actualBalances.push(readU64LE(data, off));
|
|
73
154
|
off += 8;
|
|
74
|
-
}
|
|
75
|
-
const swapFeeRate = data.readUInt32LE(off);
|
|
76
|
-
off += 4;
|
|
77
|
-
const protocolFeeRate = data.readUInt16LE(off);
|
|
78
|
-
off += 2;
|
|
79
|
-
const protocolFeesOwed: BN[] = [];
|
|
80
|
-
for (let i = 0; i < MAX_TOKENS; i++) {
|
|
81
155
|
protocolFeesOwed.push(readU64LE(data, off));
|
|
82
156
|
off += 8;
|
|
157
|
+
previousSelloff.push(readU64LE(data, off));
|
|
158
|
+
off += 8;
|
|
159
|
+
currentSelloff.push(readU64LE(data, off));
|
|
160
|
+
off += 8;
|
|
161
|
+
windowStartTimestamp.push(readI64LE(data, off));
|
|
162
|
+
off += 8;
|
|
163
|
+
off += 8; // AssetDynamics.reserved
|
|
83
164
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
off += 1;
|
|
90
|
-
// reserved[128] trails — ignored.
|
|
165
|
+
|
|
166
|
+
const lookupTable = readPubkey(data, off);
|
|
167
|
+
off += 32;
|
|
168
|
+
|
|
169
|
+
// Trailing `reserved[32]` ignored.
|
|
91
170
|
|
|
92
171
|
return {
|
|
93
172
|
config,
|
|
94
173
|
bump,
|
|
95
174
|
tokenCount,
|
|
96
175
|
poolId,
|
|
176
|
+
swapFeeRate,
|
|
177
|
+
protocolFeeRate,
|
|
178
|
+
createdAt,
|
|
179
|
+
poolEnabled,
|
|
180
|
+
swapsEnabled,
|
|
181
|
+
poolAdmin,
|
|
182
|
+
pendingPoolAdmin,
|
|
183
|
+
rangeManager,
|
|
184
|
+
rangeManagerEnabled,
|
|
185
|
+
rangeManagerMaxVbChangeBps,
|
|
186
|
+
rangeManagerMaxWeightChangeBps,
|
|
187
|
+
rangeManagerMinUpdateIntervalSecs,
|
|
188
|
+
rangeManagerLastUpdated,
|
|
97
189
|
tokenMints,
|
|
98
190
|
tokenPrograms,
|
|
99
191
|
normalizedWeights,
|
|
192
|
+
maxSelloff,
|
|
193
|
+
maxSelloffPeriodLength,
|
|
100
194
|
virtualBalances,
|
|
101
195
|
actualBalances,
|
|
102
|
-
swapFeeRate,
|
|
103
|
-
protocolFeeRate,
|
|
104
196
|
protocolFeesOwed,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
197
|
+
previousSelloff,
|
|
198
|
+
currentSelloff,
|
|
199
|
+
windowStartTimestamp,
|
|
200
|
+
lookupTable,
|
|
108
201
|
};
|
|
109
202
|
}
|
|
110
203
|
|
|
204
|
+
function readPubkey(data: Buffer, off: number): PublicKey {
|
|
205
|
+
return new PublicKey(data.slice(off, off + 32));
|
|
206
|
+
}
|
|
207
|
+
|
|
111
208
|
function readU64LE(data: Buffer, off: number): BN {
|
|
112
209
|
return new BN(data.slice(off, off + 8), "le");
|
|
113
210
|
}
|
|
211
|
+
|
|
212
|
+
function readI64LE(data: Buffer, off: number): BN {
|
|
213
|
+
// i64 LE — for our timestamps (always ≥ 0 in practice) BN+LE matches.
|
|
214
|
+
// Returning BN keeps callers free to interpret signedness if needed.
|
|
215
|
+
return new BN(data.slice(off, off + 8), "le");
|
|
216
|
+
}
|
package/src/types/pool.ts
CHANGED
|
@@ -50,6 +50,12 @@ export interface PoolInfo {
|
|
|
50
50
|
poolEnabled: boolean;
|
|
51
51
|
swapsEnabled: boolean;
|
|
52
52
|
createdAt: number;
|
|
53
|
+
/**
|
|
54
|
+
* Per-pool Address Lookup Table. `PublicKey.default` ⇒ no ALT provisioned
|
|
55
|
+
* yet (call `initialize_pool_alt` to bootstrap). When set and non-default,
|
|
56
|
+
* v0-tx builders compress per-token accounts via this ALT.
|
|
57
|
+
*/
|
|
58
|
+
lookupTable: PublicKey;
|
|
53
59
|
/** Unix timestamp (ms) when sync() ran. Useful for staleness checks. */
|
|
54
60
|
syncedAt: number;
|
|
55
61
|
}
|