@hadron-fi/sdk 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/dist/index.d.mts +676 -0
- package/dist/index.d.ts +676 -0
- package/dist/index.js +1653 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1653 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +43 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1653 @@
|
|
|
1
|
+
// src/constants/index.ts
|
|
2
|
+
import { PublicKey } from "@solana/web3.js";
|
|
3
|
+
var HADRON_PROGRAM_ID = new PublicKey(
|
|
4
|
+
"Q72w4coozA552keKDdeeh2EyQw32qfMFsHPu6cbatom"
|
|
5
|
+
);
|
|
6
|
+
var CONFIG_SEED = Buffer.from("hadron-config");
|
|
7
|
+
var MIDPRICE_ORACLE_SEED = Buffer.from("hadron-midprice");
|
|
8
|
+
var CURVE_META_SEED = Buffer.from("hadron-curve-meta");
|
|
9
|
+
var CURVE_PREFABS_SEED = Buffer.from("hadron-curve-prefabs");
|
|
10
|
+
var CURVE_UPDATES_SEED = Buffer.from("hadron-curve-updates");
|
|
11
|
+
var FEE_CONFIG_SEED = Buffer.from("fee_config");
|
|
12
|
+
var SPREAD_CONFIG_SEED = Buffer.from("spread_config");
|
|
13
|
+
var CONFIG_SIZE = 248;
|
|
14
|
+
var MIDPRICE_ORACLE_SIZE = 64;
|
|
15
|
+
var CURVE_META_SIZE = 48;
|
|
16
|
+
var FEE_CONFIG_SIZE = 72;
|
|
17
|
+
var CURVE_UPDATES_SIZE = 258;
|
|
18
|
+
var CURVE_SIDE_HEADER = 8;
|
|
19
|
+
var CURVE_POINT_LEN = 24;
|
|
20
|
+
var DEFAULT_MAX_PREFAB_SLOTS = 10;
|
|
21
|
+
var DEFAULT_MAX_CURVE_POINTS = 16;
|
|
22
|
+
var ABSOLUTE_MAX_PREFAB_SLOTS = 16;
|
|
23
|
+
var ABSOLUTE_MAX_CURVE_POINTS = 128;
|
|
24
|
+
var MAX_SETCURVE_POINTS = 32;
|
|
25
|
+
var MAX_CURVE_UPDATE_OPS = 8;
|
|
26
|
+
var Q32_ONE = BigInt(1) << BigInt(32);
|
|
27
|
+
var Discriminator = {
|
|
28
|
+
Initialize: 0,
|
|
29
|
+
Deposit: 1,
|
|
30
|
+
Withdraw: 2,
|
|
31
|
+
SwapExactIn: 3,
|
|
32
|
+
SetCurve: 4,
|
|
33
|
+
UpdateMidprice: 5,
|
|
34
|
+
InitializeFeeConfig: 6,
|
|
35
|
+
UpdateFeeConfig: 7,
|
|
36
|
+
SetRiskCurve: 8,
|
|
37
|
+
UpdateBaseSpread: 9,
|
|
38
|
+
UpdateMidpriceAndBaseSpread: 10,
|
|
39
|
+
SwitchPriceCurve: 11,
|
|
40
|
+
SwitchRiskCurve: 12,
|
|
41
|
+
InitializeSpreadConfig: 13,
|
|
42
|
+
UpdateSpreadConfig: 14,
|
|
43
|
+
UpdateDeltaStaleness: 15,
|
|
44
|
+
NominateAuthority: 16,
|
|
45
|
+
AcceptAuthority: 17,
|
|
46
|
+
SubmitCurveUpdates: 18,
|
|
47
|
+
ApplyCurveUpdates: 19,
|
|
48
|
+
ClosePool: 20,
|
|
49
|
+
SetPoolState: 21,
|
|
50
|
+
AllocateCurvePrefabs: 22,
|
|
51
|
+
SetQuotingAuthority: 23,
|
|
52
|
+
RotateFeeAdmin: 24
|
|
53
|
+
};
|
|
54
|
+
var POINT_DATA_SIZE = 21;
|
|
55
|
+
var CURVE_UPDATE_OP_SIZE = 24;
|
|
56
|
+
function curvePrefabsSize(maxSlots, maxPoints) {
|
|
57
|
+
return 32 + 4 * maxSlots * (CURVE_SIDE_HEADER + maxPoints * CURVE_POINT_LEN);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/helpers/derive.ts
|
|
61
|
+
import { PublicKey as PublicKey2 } from "@solana/web3.js";
|
|
62
|
+
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
|
|
63
|
+
function seedToBuffer(seed) {
|
|
64
|
+
const buf = Buffer.alloc(8);
|
|
65
|
+
buf.writeBigUInt64LE(seed);
|
|
66
|
+
return buf;
|
|
67
|
+
}
|
|
68
|
+
function getConfigAddress(seed, mintX, mintY, programId = HADRON_PROGRAM_ID) {
|
|
69
|
+
return PublicKey2.findProgramAddressSync(
|
|
70
|
+
[CONFIG_SEED, seedToBuffer(seed), mintX.toBuffer(), mintY.toBuffer()],
|
|
71
|
+
programId
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
function getMidpriceOracleAddress(seed, mintX, mintY, programId = HADRON_PROGRAM_ID) {
|
|
75
|
+
return PublicKey2.findProgramAddressSync(
|
|
76
|
+
[
|
|
77
|
+
MIDPRICE_ORACLE_SEED,
|
|
78
|
+
seedToBuffer(seed),
|
|
79
|
+
mintX.toBuffer(),
|
|
80
|
+
mintY.toBuffer()
|
|
81
|
+
],
|
|
82
|
+
programId
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
function getCurveMetaAddress(seed, mintX, mintY, programId = HADRON_PROGRAM_ID) {
|
|
86
|
+
return PublicKey2.findProgramAddressSync(
|
|
87
|
+
[CURVE_META_SEED, seedToBuffer(seed), mintX.toBuffer(), mintY.toBuffer()],
|
|
88
|
+
programId
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
function getCurvePrefabsAddress(seed, mintX, mintY, programId = HADRON_PROGRAM_ID) {
|
|
92
|
+
return PublicKey2.findProgramAddressSync(
|
|
93
|
+
[
|
|
94
|
+
CURVE_PREFABS_SEED,
|
|
95
|
+
seedToBuffer(seed),
|
|
96
|
+
mintX.toBuffer(),
|
|
97
|
+
mintY.toBuffer()
|
|
98
|
+
],
|
|
99
|
+
programId
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
function getCurveUpdatesAddress(seed, mintX, mintY, programId = HADRON_PROGRAM_ID) {
|
|
103
|
+
return PublicKey2.findProgramAddressSync(
|
|
104
|
+
[
|
|
105
|
+
CURVE_UPDATES_SEED,
|
|
106
|
+
seedToBuffer(seed),
|
|
107
|
+
mintX.toBuffer(),
|
|
108
|
+
mintY.toBuffer()
|
|
109
|
+
],
|
|
110
|
+
programId
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
function getFeeConfigAddress(programId = HADRON_PROGRAM_ID) {
|
|
114
|
+
return PublicKey2.findProgramAddressSync([FEE_CONFIG_SEED], programId);
|
|
115
|
+
}
|
|
116
|
+
function getSpreadConfigAddress(configPda, programId = HADRON_PROGRAM_ID) {
|
|
117
|
+
return PublicKey2.findProgramAddressSync(
|
|
118
|
+
[SPREAD_CONFIG_SEED, configPda.toBuffer()],
|
|
119
|
+
programId
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
function derivePoolAddresses(seed, mintX, mintY, tokenProgramX, tokenProgramY, programId = HADRON_PROGRAM_ID) {
|
|
123
|
+
const [config, configBump] = getConfigAddress(seed, mintX, mintY, programId);
|
|
124
|
+
const [midpriceOracle] = getMidpriceOracleAddress(
|
|
125
|
+
seed,
|
|
126
|
+
mintX,
|
|
127
|
+
mintY,
|
|
128
|
+
programId
|
|
129
|
+
);
|
|
130
|
+
const [curveMeta] = getCurveMetaAddress(seed, mintX, mintY, programId);
|
|
131
|
+
const [curvePrefabs] = getCurvePrefabsAddress(seed, mintX, mintY, programId);
|
|
132
|
+
const [curveUpdates] = getCurveUpdatesAddress(seed, mintX, mintY, programId);
|
|
133
|
+
const vaultX = getAssociatedTokenAddressSync(
|
|
134
|
+
mintX,
|
|
135
|
+
config,
|
|
136
|
+
true,
|
|
137
|
+
tokenProgramX
|
|
138
|
+
);
|
|
139
|
+
const vaultY = getAssociatedTokenAddressSync(
|
|
140
|
+
mintY,
|
|
141
|
+
config,
|
|
142
|
+
true,
|
|
143
|
+
tokenProgramY
|
|
144
|
+
);
|
|
145
|
+
return {
|
|
146
|
+
config,
|
|
147
|
+
configBump,
|
|
148
|
+
midpriceOracle,
|
|
149
|
+
curveMeta,
|
|
150
|
+
curvePrefabs,
|
|
151
|
+
curveUpdates,
|
|
152
|
+
vaultX,
|
|
153
|
+
vaultY
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// src/helpers/math.ts
|
|
158
|
+
function toQ32(value) {
|
|
159
|
+
return BigInt(Math.floor(value * Number(Q32_ONE)));
|
|
160
|
+
}
|
|
161
|
+
function fromQ32(q32) {
|
|
162
|
+
const intPart = q32 >> 32n;
|
|
163
|
+
const fracPart = q32 & 0xFFFFFFFFn;
|
|
164
|
+
return Number(intPart) + Number(fracPart) / Number(Q32_ONE);
|
|
165
|
+
}
|
|
166
|
+
function pctToQ32(pct) {
|
|
167
|
+
return toQ32(pct);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// src/accounts/index.ts
|
|
171
|
+
import { PublicKey as PublicKey3 } from "@solana/web3.js";
|
|
172
|
+
|
|
173
|
+
// src/types/index.ts
|
|
174
|
+
var PoolState = /* @__PURE__ */ ((PoolState3) => {
|
|
175
|
+
PoolState3[PoolState3["Uninitialized"] = 0] = "Uninitialized";
|
|
176
|
+
PoolState3[PoolState3["Initialized"] = 1] = "Initialized";
|
|
177
|
+
PoolState3[PoolState3["Paused"] = 2] = "Paused";
|
|
178
|
+
PoolState3[PoolState3["WithdrawOnly"] = 3] = "WithdrawOnly";
|
|
179
|
+
return PoolState3;
|
|
180
|
+
})(PoolState || {});
|
|
181
|
+
var OracleMode = /* @__PURE__ */ ((OracleMode3) => {
|
|
182
|
+
OracleMode3[OracleMode3["Authority"] = 0] = "Authority";
|
|
183
|
+
OracleMode3[OracleMode3["Relative"] = 1] = "Relative";
|
|
184
|
+
return OracleMode3;
|
|
185
|
+
})(OracleMode || {});
|
|
186
|
+
var Interpolation = /* @__PURE__ */ ((Interpolation4) => {
|
|
187
|
+
Interpolation4[Interpolation4["Step"] = 0] = "Step";
|
|
188
|
+
Interpolation4[Interpolation4["Linear"] = 1] = "Linear";
|
|
189
|
+
Interpolation4[Interpolation4["MarginalStep"] = 2] = "MarginalStep";
|
|
190
|
+
Interpolation4[Interpolation4["Hyperbolic"] = 3] = "Hyperbolic";
|
|
191
|
+
Interpolation4[Interpolation4["Quadratic"] = 4] = "Quadratic";
|
|
192
|
+
Interpolation4[Interpolation4["Cubic"] = 5] = "Cubic";
|
|
193
|
+
return Interpolation4;
|
|
194
|
+
})(Interpolation || {});
|
|
195
|
+
var CurveType = /* @__PURE__ */ ((CurveType2) => {
|
|
196
|
+
CurveType2[CurveType2["PriceBid"] = 0] = "PriceBid";
|
|
197
|
+
CurveType2[CurveType2["PriceAsk"] = 1] = "PriceAsk";
|
|
198
|
+
CurveType2[CurveType2["RiskBid"] = 2] = "RiskBid";
|
|
199
|
+
CurveType2[CurveType2["RiskAsk"] = 3] = "RiskAsk";
|
|
200
|
+
return CurveType2;
|
|
201
|
+
})(CurveType || {});
|
|
202
|
+
var CurveXMode = /* @__PURE__ */ ((CurveXMode3) => {
|
|
203
|
+
CurveXMode3[CurveXMode3["Native"] = 0] = "Native";
|
|
204
|
+
CurveXMode3[CurveXMode3["Alternate"] = 1] = "Alternate";
|
|
205
|
+
return CurveXMode3;
|
|
206
|
+
})(CurveXMode || {});
|
|
207
|
+
var RiskMode = /* @__PURE__ */ ((RiskMode3) => {
|
|
208
|
+
RiskMode3[RiskMode3["Virtual"] = 0] = "Virtual";
|
|
209
|
+
RiskMode3[RiskMode3["Integrated"] = 1] = "Integrated";
|
|
210
|
+
return RiskMode3;
|
|
211
|
+
})(RiskMode || {});
|
|
212
|
+
var CurveUpdateOpKind = /* @__PURE__ */ ((CurveUpdateOpKind3) => {
|
|
213
|
+
CurveUpdateOpKind3[CurveUpdateOpKind3["Edit"] = 0] = "Edit";
|
|
214
|
+
CurveUpdateOpKind3[CurveUpdateOpKind3["Add"] = 1] = "Add";
|
|
215
|
+
CurveUpdateOpKind3[CurveUpdateOpKind3["Remove"] = 2] = "Remove";
|
|
216
|
+
return CurveUpdateOpKind3;
|
|
217
|
+
})(CurveUpdateOpKind || {});
|
|
218
|
+
var Side = /* @__PURE__ */ ((Side2) => {
|
|
219
|
+
Side2[Side2["Bid"] = 0] = "Bid";
|
|
220
|
+
Side2[Side2["Ask"] = 1] = "Ask";
|
|
221
|
+
return Side2;
|
|
222
|
+
})(Side || {});
|
|
223
|
+
|
|
224
|
+
// src/accounts/index.ts
|
|
225
|
+
function decodeConfig(data) {
|
|
226
|
+
const buf = Buffer.from(data);
|
|
227
|
+
let offset = 0;
|
|
228
|
+
const state = buf.readUInt8(offset);
|
|
229
|
+
offset += 1;
|
|
230
|
+
const seed = buf.readBigUInt64LE(offset);
|
|
231
|
+
offset += 8;
|
|
232
|
+
const authority = new PublicKey3(buf.subarray(offset, offset + 32));
|
|
233
|
+
offset += 32;
|
|
234
|
+
const mintX = new PublicKey3(buf.subarray(offset, offset + 32));
|
|
235
|
+
offset += 32;
|
|
236
|
+
const mintY = new PublicKey3(buf.subarray(offset, offset + 32));
|
|
237
|
+
offset += 32;
|
|
238
|
+
const configBump = buf.readUInt8(offset);
|
|
239
|
+
offset += 1;
|
|
240
|
+
const curveMeta = new PublicKey3(buf.subarray(offset, offset + 32));
|
|
241
|
+
offset += 32;
|
|
242
|
+
const spreadConfigInitialized = buf.readUInt8(offset) !== 0;
|
|
243
|
+
offset += 1;
|
|
244
|
+
const deltaStaleness = buf.readUInt8(offset);
|
|
245
|
+
offset += 1;
|
|
246
|
+
const oracleMode = buf.readUInt8(offset);
|
|
247
|
+
offset += 1;
|
|
248
|
+
offset += 3;
|
|
249
|
+
const pendingAuthority = new PublicKey3(buf.subarray(offset, offset + 32));
|
|
250
|
+
offset += 32;
|
|
251
|
+
const nominationExpiry = buf.readBigUInt64LE(offset);
|
|
252
|
+
offset += 8;
|
|
253
|
+
const tokenProgramX = new PublicKey3(buf.subarray(offset, offset + 32));
|
|
254
|
+
offset += 32;
|
|
255
|
+
const tokenProgramY = new PublicKey3(buf.subarray(offset, offset + 32));
|
|
256
|
+
return {
|
|
257
|
+
state,
|
|
258
|
+
seed,
|
|
259
|
+
authority,
|
|
260
|
+
mintX,
|
|
261
|
+
mintY,
|
|
262
|
+
configBump,
|
|
263
|
+
curveMeta,
|
|
264
|
+
spreadConfigInitialized,
|
|
265
|
+
deltaStaleness,
|
|
266
|
+
oracleMode,
|
|
267
|
+
pendingAuthority,
|
|
268
|
+
nominationExpiry,
|
|
269
|
+
tokenProgramX,
|
|
270
|
+
tokenProgramY
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
function decodeMidpriceOracle(data) {
|
|
274
|
+
const buf = Buffer.from(data);
|
|
275
|
+
const authority = new PublicKey3(buf.subarray(0, 32));
|
|
276
|
+
const sequence = buf.readBigUInt64LE(32);
|
|
277
|
+
const midpriceQ32 = buf.readBigUInt64LE(40);
|
|
278
|
+
const baseSpreadQ32 = buf.readBigUInt64LE(48);
|
|
279
|
+
const lastUpdateSlot = buf.length >= MIDPRICE_ORACLE_SIZE ? buf.readBigUInt64LE(56) : 0n;
|
|
280
|
+
return { authority, sequence, midpriceQ32, baseSpreadQ32, lastUpdateSlot };
|
|
281
|
+
}
|
|
282
|
+
function decodeCurveMeta(data) {
|
|
283
|
+
const buf = Buffer.from(data);
|
|
284
|
+
return {
|
|
285
|
+
authority: new PublicKey3(buf.subarray(0, 32)),
|
|
286
|
+
activePriceBidSlot: buf.readUInt8(32),
|
|
287
|
+
activePriceAskSlot: buf.readUInt8(33),
|
|
288
|
+
activeRiskBidSlot: buf.readUInt8(34),
|
|
289
|
+
activeRiskAskSlot: buf.readUInt8(35),
|
|
290
|
+
initializedSlots: new Uint8Array(buf.subarray(36, 44)),
|
|
291
|
+
maxPrefabSlots: buf.readUInt8(44),
|
|
292
|
+
maxCurvePoints: buf.readUInt8(45)
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
function isSlotInitialized(initializedSlots, curveType, slot, maxSlots) {
|
|
296
|
+
const bitIndex = curveType * maxSlots + slot;
|
|
297
|
+
const byteIndex = Math.floor(bitIndex / 8);
|
|
298
|
+
const bitOffset = bitIndex % 8;
|
|
299
|
+
return (initializedSlots[byteIndex] & 1 << bitOffset) !== 0;
|
|
300
|
+
}
|
|
301
|
+
function decodeFeeConfig(data) {
|
|
302
|
+
const buf = Buffer.from(data);
|
|
303
|
+
return {
|
|
304
|
+
initialized: buf.readUInt8(0) !== 0,
|
|
305
|
+
feePpm: buf.readUInt32LE(1),
|
|
306
|
+
bump: buf.readUInt8(5),
|
|
307
|
+
// skip 2 bytes padding
|
|
308
|
+
feeAdmin: new PublicKey3(buf.subarray(8, 40)),
|
|
309
|
+
feeRecipient: new PublicKey3(buf.subarray(40, 72))
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
function decodeCurveUpdates(data) {
|
|
313
|
+
const buf = Buffer.from(data);
|
|
314
|
+
let offset = 0;
|
|
315
|
+
const authority = new PublicKey3(buf.subarray(offset, offset + 32));
|
|
316
|
+
offset += 32;
|
|
317
|
+
const curveMeta = new PublicKey3(buf.subarray(offset, offset + 32));
|
|
318
|
+
offset += 32;
|
|
319
|
+
const numOps = buf.readUInt8(offset);
|
|
320
|
+
offset += 1;
|
|
321
|
+
offset += 1;
|
|
322
|
+
const ops = [];
|
|
323
|
+
for (let i = 0; i < numOps && i < MAX_CURVE_UPDATE_OPS; i++) {
|
|
324
|
+
const opOffset = offset + i * CURVE_UPDATE_OP_SIZE;
|
|
325
|
+
ops.push({
|
|
326
|
+
curveType: buf.readUInt8(opOffset),
|
|
327
|
+
opKind: buf.readUInt8(opOffset + 1),
|
|
328
|
+
pointIndex: buf.readUInt8(opOffset + 2),
|
|
329
|
+
interpolation: buf.readUInt8(opOffset + 3),
|
|
330
|
+
xIn: buf.readBigUInt64LE(opOffset + 4),
|
|
331
|
+
priceFactorQ32: buf.readBigUInt64LE(opOffset + 12),
|
|
332
|
+
params: new Uint8Array(buf.subarray(opOffset + 20, opOffset + 24))
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
return { authority, curveMeta, numOps, ops };
|
|
336
|
+
}
|
|
337
|
+
function decodeCurveSide(data, curveType, slot, maxSlots, maxPoints) {
|
|
338
|
+
const sideSize = CURVE_SIDE_HEADER + maxPoints * CURVE_POINT_LEN;
|
|
339
|
+
const offset = 32 + (curveType * maxSlots + slot) * sideSize;
|
|
340
|
+
const buf = Buffer.from(data);
|
|
341
|
+
const numPoints = buf.readUInt8(offset);
|
|
342
|
+
const defaultInterpolation = buf.readUInt8(offset + 1);
|
|
343
|
+
const xMode = buf.readUInt8(offset + 2);
|
|
344
|
+
const riskMode = buf.readUInt8(offset + 3);
|
|
345
|
+
const points = [];
|
|
346
|
+
const pointsStart = offset + CURVE_SIDE_HEADER;
|
|
347
|
+
const n = Math.min(numPoints, maxPoints);
|
|
348
|
+
for (let i = 0; i < n; i++) {
|
|
349
|
+
const pOff = pointsStart + i * CURVE_POINT_LEN;
|
|
350
|
+
points.push({
|
|
351
|
+
xIn: buf.readBigUInt64LE(pOff),
|
|
352
|
+
priceFactorQ32: buf.readBigUInt64LE(pOff + 8),
|
|
353
|
+
interpolation: buf.readUInt8(pOff + 16),
|
|
354
|
+
params: new Uint8Array(buf.subarray(pOff + 17, pOff + 21))
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
return { numPoints, defaultInterpolation, xMode, riskMode, points };
|
|
358
|
+
}
|
|
359
|
+
function decodeActiveCurves(prefabsData, meta) {
|
|
360
|
+
const { maxPrefabSlots, maxCurvePoints } = meta;
|
|
361
|
+
return {
|
|
362
|
+
priceBid: decodeCurveSide(
|
|
363
|
+
prefabsData,
|
|
364
|
+
0 /* PriceBid */,
|
|
365
|
+
meta.activePriceBidSlot,
|
|
366
|
+
maxPrefabSlots,
|
|
367
|
+
maxCurvePoints
|
|
368
|
+
),
|
|
369
|
+
priceAsk: decodeCurveSide(
|
|
370
|
+
prefabsData,
|
|
371
|
+
1 /* PriceAsk */,
|
|
372
|
+
meta.activePriceAskSlot,
|
|
373
|
+
maxPrefabSlots,
|
|
374
|
+
maxCurvePoints
|
|
375
|
+
),
|
|
376
|
+
riskBid: decodeCurveSide(
|
|
377
|
+
prefabsData,
|
|
378
|
+
2 /* RiskBid */,
|
|
379
|
+
meta.activeRiskBidSlot,
|
|
380
|
+
maxPrefabSlots,
|
|
381
|
+
maxCurvePoints
|
|
382
|
+
),
|
|
383
|
+
riskAsk: decodeCurveSide(
|
|
384
|
+
prefabsData,
|
|
385
|
+
3 /* RiskAsk */,
|
|
386
|
+
meta.activeRiskAskSlot,
|
|
387
|
+
maxPrefabSlots,
|
|
388
|
+
maxCurvePoints
|
|
389
|
+
)
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// src/instructions/initialize.ts
|
|
394
|
+
import {
|
|
395
|
+
PublicKey as PublicKey4,
|
|
396
|
+
SystemProgram,
|
|
397
|
+
TransactionInstruction
|
|
398
|
+
} from "@solana/web3.js";
|
|
399
|
+
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
|
400
|
+
function buildInitialize(payer, params, programId = HADRON_PROGRAM_ID) {
|
|
401
|
+
const seed = params.seed;
|
|
402
|
+
if (seed === void 0) throw new Error("seed is required \u2014 use Hadron.initialize() to auto-generate one");
|
|
403
|
+
const tokenProgramX = params.tokenProgramX ?? TOKEN_PROGRAM_ID;
|
|
404
|
+
const tokenProgramY = params.tokenProgramY ?? TOKEN_PROGRAM_ID;
|
|
405
|
+
const maxPrefabSlots = params.maxPrefabSlots ?? DEFAULT_MAX_PREFAB_SLOTS;
|
|
406
|
+
const maxCurvePoints = params.maxCurvePoints ?? DEFAULT_MAX_CURVE_POINTS;
|
|
407
|
+
const oracleMode = params.oracleMode ?? 0;
|
|
408
|
+
const addrs = derivePoolAddresses(
|
|
409
|
+
seed,
|
|
410
|
+
params.mintX,
|
|
411
|
+
params.mintY,
|
|
412
|
+
tokenProgramX,
|
|
413
|
+
tokenProgramY,
|
|
414
|
+
programId
|
|
415
|
+
);
|
|
416
|
+
const hasCustomSlots = params.maxPrefabSlots !== void 0 || params.maxCurvePoints !== void 0;
|
|
417
|
+
const hasOracleMode = oracleMode !== 0 || hasCustomSlots;
|
|
418
|
+
const trailingLen = hasCustomSlots ? 3 : hasOracleMode ? 1 : 0;
|
|
419
|
+
const data = Buffer.alloc(1 + 8 + 32 + 32 + 32 + 8 + trailingLen);
|
|
420
|
+
let offset = 0;
|
|
421
|
+
data.writeUInt8(Discriminator.Initialize, offset);
|
|
422
|
+
offset += 1;
|
|
423
|
+
data.writeBigUInt64LE(seed, offset);
|
|
424
|
+
offset += 8;
|
|
425
|
+
params.mintX.toBuffer().copy(data, offset);
|
|
426
|
+
offset += 32;
|
|
427
|
+
params.mintY.toBuffer().copy(data, offset);
|
|
428
|
+
offset += 32;
|
|
429
|
+
params.authority.toBuffer().copy(data, offset);
|
|
430
|
+
offset += 32;
|
|
431
|
+
data.writeBigUInt64LE(params.initialMidpriceQ32, offset);
|
|
432
|
+
offset += 8;
|
|
433
|
+
if (hasOracleMode) {
|
|
434
|
+
data.writeUInt8(oracleMode, offset);
|
|
435
|
+
offset += 1;
|
|
436
|
+
}
|
|
437
|
+
if (hasCustomSlots) {
|
|
438
|
+
data.writeUInt8(maxPrefabSlots, offset);
|
|
439
|
+
offset += 1;
|
|
440
|
+
data.writeUInt8(maxCurvePoints, offset);
|
|
441
|
+
}
|
|
442
|
+
return new TransactionInstruction({
|
|
443
|
+
programId,
|
|
444
|
+
keys: [
|
|
445
|
+
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
446
|
+
{ pubkey: addrs.config, isSigner: false, isWritable: true },
|
|
447
|
+
{ pubkey: params.mintX, isSigner: false, isWritable: false },
|
|
448
|
+
{ pubkey: params.mintY, isSigner: false, isWritable: false },
|
|
449
|
+
{ pubkey: addrs.vaultX, isSigner: false, isWritable: true },
|
|
450
|
+
{ pubkey: addrs.vaultY, isSigner: false, isWritable: true },
|
|
451
|
+
{ pubkey: tokenProgramX, isSigner: false, isWritable: false },
|
|
452
|
+
{ pubkey: tokenProgramY, isSigner: false, isWritable: false },
|
|
453
|
+
{
|
|
454
|
+
pubkey: ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
455
|
+
isSigner: false,
|
|
456
|
+
isWritable: false
|
|
457
|
+
},
|
|
458
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
459
|
+
{ pubkey: addrs.midpriceOracle, isSigner: false, isWritable: true },
|
|
460
|
+
{ pubkey: addrs.curveMeta, isSigner: false, isWritable: true },
|
|
461
|
+
{ pubkey: addrs.curvePrefabs, isSigner: false, isWritable: true },
|
|
462
|
+
{ pubkey: addrs.curveUpdates, isSigner: false, isWritable: true }
|
|
463
|
+
],
|
|
464
|
+
data
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
function buildAllocateCurvePrefabs(payer, params, programId = HADRON_PROGRAM_ID) {
|
|
468
|
+
const maxPrefabSlots = params.maxPrefabSlots ?? DEFAULT_MAX_PREFAB_SLOTS;
|
|
469
|
+
const maxCurvePoints = params.maxCurvePoints ?? DEFAULT_MAX_CURVE_POINTS;
|
|
470
|
+
const data = Buffer.alloc(1 + 8 + 32 + 32 + 1 + 1);
|
|
471
|
+
let offset = 0;
|
|
472
|
+
data.writeUInt8(Discriminator.AllocateCurvePrefabs, offset);
|
|
473
|
+
offset += 1;
|
|
474
|
+
data.writeBigUInt64LE(params.seed, offset);
|
|
475
|
+
offset += 8;
|
|
476
|
+
params.mintX.toBuffer().copy(data, offset);
|
|
477
|
+
offset += 32;
|
|
478
|
+
params.mintY.toBuffer().copy(data, offset);
|
|
479
|
+
offset += 32;
|
|
480
|
+
data.writeUInt8(maxPrefabSlots, offset);
|
|
481
|
+
offset += 1;
|
|
482
|
+
data.writeUInt8(maxCurvePoints, offset);
|
|
483
|
+
const [curvePrefabsPda] = PublicKey4.findProgramAddressSync(
|
|
484
|
+
[
|
|
485
|
+
Buffer.from("hadron-curve-prefabs"),
|
|
486
|
+
(() => {
|
|
487
|
+
const b = Buffer.alloc(8);
|
|
488
|
+
b.writeBigUInt64LE(params.seed);
|
|
489
|
+
return b;
|
|
490
|
+
})(),
|
|
491
|
+
params.mintX.toBuffer(),
|
|
492
|
+
params.mintY.toBuffer()
|
|
493
|
+
],
|
|
494
|
+
programId
|
|
495
|
+
);
|
|
496
|
+
return new TransactionInstruction({
|
|
497
|
+
programId,
|
|
498
|
+
keys: [
|
|
499
|
+
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
500
|
+
{ pubkey: curvePrefabsPda, isSigner: false, isWritable: true },
|
|
501
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false }
|
|
502
|
+
],
|
|
503
|
+
data
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// src/instructions/deposit.ts
|
|
508
|
+
import { TransactionInstruction as TransactionInstruction2 } from "@solana/web3.js";
|
|
509
|
+
import { getAssociatedTokenAddressSync as getAssociatedTokenAddressSync2 } from "@solana/spl-token";
|
|
510
|
+
function buildDeposit(user, configPda, mintX, mintY, tokenProgramX, tokenProgramY, params, programId = HADRON_PROGRAM_ID) {
|
|
511
|
+
const data = Buffer.alloc(1 + 8 + 8 + 8);
|
|
512
|
+
let offset = 0;
|
|
513
|
+
data.writeUInt8(Discriminator.Deposit, offset);
|
|
514
|
+
offset += 1;
|
|
515
|
+
data.writeBigUInt64LE(params.amountX, offset);
|
|
516
|
+
offset += 8;
|
|
517
|
+
data.writeBigUInt64LE(params.amountY, offset);
|
|
518
|
+
offset += 8;
|
|
519
|
+
const exp = params.expiration ?? Math.floor(Date.now() / 1e3) + 3600;
|
|
520
|
+
data.writeBigInt64LE(BigInt(exp), offset);
|
|
521
|
+
const userX = getAssociatedTokenAddressSync2(mintX, user, false, tokenProgramX);
|
|
522
|
+
const userY = getAssociatedTokenAddressSync2(mintY, user, false, tokenProgramY);
|
|
523
|
+
const vaultX = getAssociatedTokenAddressSync2(mintX, configPda, true, tokenProgramX);
|
|
524
|
+
const vaultY = getAssociatedTokenAddressSync2(mintY, configPda, true, tokenProgramY);
|
|
525
|
+
return new TransactionInstruction2({
|
|
526
|
+
programId,
|
|
527
|
+
keys: [
|
|
528
|
+
{ pubkey: user, isSigner: true, isWritable: false },
|
|
529
|
+
{ pubkey: vaultX, isSigner: false, isWritable: true },
|
|
530
|
+
{ pubkey: vaultY, isSigner: false, isWritable: true },
|
|
531
|
+
{ pubkey: userX, isSigner: false, isWritable: true },
|
|
532
|
+
{ pubkey: userY, isSigner: false, isWritable: true },
|
|
533
|
+
{ pubkey: configPda, isSigner: false, isWritable: false },
|
|
534
|
+
{ pubkey: tokenProgramX, isSigner: false, isWritable: false },
|
|
535
|
+
{ pubkey: tokenProgramY, isSigner: false, isWritable: false }
|
|
536
|
+
],
|
|
537
|
+
data
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// src/instructions/withdraw.ts
|
|
542
|
+
import { TransactionInstruction as TransactionInstruction3 } from "@solana/web3.js";
|
|
543
|
+
import { getAssociatedTokenAddressSync as getAssociatedTokenAddressSync3 } from "@solana/spl-token";
|
|
544
|
+
function buildWithdraw(user, configPda, mintX, mintY, tokenProgramX, tokenProgramY, params, programId = HADRON_PROGRAM_ID) {
|
|
545
|
+
const data = Buffer.alloc(1 + 8 + 8 + 8);
|
|
546
|
+
let offset = 0;
|
|
547
|
+
data.writeUInt8(Discriminator.Withdraw, offset);
|
|
548
|
+
offset += 1;
|
|
549
|
+
data.writeBigUInt64LE(params.amountX, offset);
|
|
550
|
+
offset += 8;
|
|
551
|
+
data.writeBigUInt64LE(params.amountY, offset);
|
|
552
|
+
offset += 8;
|
|
553
|
+
const exp = params.expiration ?? Math.floor(Date.now() / 1e3) + 3600;
|
|
554
|
+
data.writeBigInt64LE(BigInt(exp), offset);
|
|
555
|
+
const userX = getAssociatedTokenAddressSync3(mintX, user, false, tokenProgramX);
|
|
556
|
+
const userY = getAssociatedTokenAddressSync3(mintY, user, false, tokenProgramY);
|
|
557
|
+
const vaultX = getAssociatedTokenAddressSync3(mintX, configPda, true, tokenProgramX);
|
|
558
|
+
const vaultY = getAssociatedTokenAddressSync3(mintY, configPda, true, tokenProgramY);
|
|
559
|
+
return new TransactionInstruction3({
|
|
560
|
+
programId,
|
|
561
|
+
keys: [
|
|
562
|
+
{ pubkey: user, isSigner: true, isWritable: false },
|
|
563
|
+
{ pubkey: vaultX, isSigner: false, isWritable: true },
|
|
564
|
+
{ pubkey: vaultY, isSigner: false, isWritable: true },
|
|
565
|
+
{ pubkey: userX, isSigner: false, isWritable: true },
|
|
566
|
+
{ pubkey: userY, isSigner: false, isWritable: true },
|
|
567
|
+
{ pubkey: configPda, isSigner: false, isWritable: true },
|
|
568
|
+
{ pubkey: tokenProgramX, isSigner: false, isWritable: false },
|
|
569
|
+
{ pubkey: tokenProgramY, isSigner: false, isWritable: false }
|
|
570
|
+
],
|
|
571
|
+
data
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// src/instructions/swap.ts
|
|
576
|
+
import {
|
|
577
|
+
SYSVAR_CLOCK_PUBKEY,
|
|
578
|
+
TransactionInstruction as TransactionInstruction4
|
|
579
|
+
} from "@solana/web3.js";
|
|
580
|
+
import { getAssociatedTokenAddressSync as getAssociatedTokenAddressSync4 } from "@solana/spl-token";
|
|
581
|
+
function buildSwapExactIn(user, poolAddresses, mintX, mintY, tokenProgramX, tokenProgramY, params, programId = HADRON_PROGRAM_ID) {
|
|
582
|
+
const data = Buffer.alloc(1 + 1 + 8 + 8 + 8);
|
|
583
|
+
let offset = 0;
|
|
584
|
+
data.writeUInt8(Discriminator.SwapExactIn, offset);
|
|
585
|
+
offset += 1;
|
|
586
|
+
data.writeUInt8(params.isX ? 1 : 0, offset);
|
|
587
|
+
offset += 1;
|
|
588
|
+
data.writeBigUInt64LE(params.amountIn, offset);
|
|
589
|
+
offset += 8;
|
|
590
|
+
data.writeBigUInt64LE(params.minOut, offset);
|
|
591
|
+
offset += 8;
|
|
592
|
+
const exp = params.expiration ?? Math.floor(Date.now() / 1e3) + 3600;
|
|
593
|
+
data.writeBigInt64LE(BigInt(exp), offset);
|
|
594
|
+
const userX = getAssociatedTokenAddressSync4(mintX, user, false, tokenProgramX);
|
|
595
|
+
const userY = getAssociatedTokenAddressSync4(mintY, user, false, tokenProgramY);
|
|
596
|
+
const [userSource, vaultSource, vaultDest, userDest] = params.isX ? [userX, poolAddresses.vaultX, poolAddresses.vaultY, userY] : [userY, poolAddresses.vaultY, poolAddresses.vaultX, userX];
|
|
597
|
+
const [feeConfigPda] = getFeeConfigAddress(programId);
|
|
598
|
+
const inputMint = params.isX ? mintX : mintY;
|
|
599
|
+
const inputMintProgram = params.isX ? tokenProgramX : tokenProgramY;
|
|
600
|
+
const feeRecipientAta = getAssociatedTokenAddressSync4(
|
|
601
|
+
inputMint,
|
|
602
|
+
params.feeRecipient,
|
|
603
|
+
false,
|
|
604
|
+
inputMintProgram
|
|
605
|
+
);
|
|
606
|
+
return new TransactionInstruction4({
|
|
607
|
+
programId,
|
|
608
|
+
keys: [
|
|
609
|
+
{ pubkey: tokenProgramX, isSigner: false, isWritable: false },
|
|
610
|
+
{ pubkey: tokenProgramY, isSigner: false, isWritable: false },
|
|
611
|
+
{ pubkey: poolAddresses.config, isSigner: false, isWritable: false },
|
|
612
|
+
{
|
|
613
|
+
pubkey: poolAddresses.midpriceOracle,
|
|
614
|
+
isSigner: false,
|
|
615
|
+
isWritable: false
|
|
616
|
+
},
|
|
617
|
+
{ pubkey: poolAddresses.curveMeta, isSigner: false, isWritable: false },
|
|
618
|
+
{
|
|
619
|
+
pubkey: poolAddresses.curvePrefabs,
|
|
620
|
+
isSigner: false,
|
|
621
|
+
isWritable: true
|
|
622
|
+
},
|
|
623
|
+
{ pubkey: poolAddresses.config, isSigner: false, isWritable: false },
|
|
624
|
+
// authority = pool address PDA
|
|
625
|
+
{ pubkey: user, isSigner: true, isWritable: false },
|
|
626
|
+
{ pubkey: userSource, isSigner: false, isWritable: true },
|
|
627
|
+
{ pubkey: vaultSource, isSigner: false, isWritable: true },
|
|
628
|
+
{ pubkey: vaultDest, isSigner: false, isWritable: true },
|
|
629
|
+
{ pubkey: userDest, isSigner: false, isWritable: true },
|
|
630
|
+
{ pubkey: feeConfigPda, isSigner: false, isWritable: false },
|
|
631
|
+
{ pubkey: feeRecipientAta, isSigner: false, isWritable: true },
|
|
632
|
+
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false },
|
|
633
|
+
{
|
|
634
|
+
pubkey: poolAddresses.curveUpdates,
|
|
635
|
+
isSigner: false,
|
|
636
|
+
isWritable: true
|
|
637
|
+
}
|
|
638
|
+
],
|
|
639
|
+
data
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// src/instructions/setCurve.ts
|
|
644
|
+
import { TransactionInstruction as TransactionInstruction5 } from "@solana/web3.js";
|
|
645
|
+
function interpolationToByte(interp) {
|
|
646
|
+
return interp;
|
|
647
|
+
}
|
|
648
|
+
function buildSetCurve(authority, curveMetaPda, curvePrefabsPda, params, programId = HADRON_PROGRAM_ID) {
|
|
649
|
+
const slot = params.slot ?? 0;
|
|
650
|
+
const xMode = params.xMode ?? 0 /* Native */;
|
|
651
|
+
const numPoints = params.points.length;
|
|
652
|
+
const data = Buffer.alloc(1 + 1 + 1 + 1 + 1 + 1 + numPoints * POINT_DATA_SIZE);
|
|
653
|
+
let offset = 0;
|
|
654
|
+
data.writeUInt8(Discriminator.SetCurve, offset);
|
|
655
|
+
offset += 1;
|
|
656
|
+
data.writeUInt8(slot, offset);
|
|
657
|
+
offset += 1;
|
|
658
|
+
data.writeUInt8(params.side, offset);
|
|
659
|
+
offset += 1;
|
|
660
|
+
data.writeUInt8(interpolationToByte(params.defaultInterpolation), offset);
|
|
661
|
+
offset += 1;
|
|
662
|
+
data.writeUInt8(numPoints, offset);
|
|
663
|
+
offset += 1;
|
|
664
|
+
data.writeUInt8(xMode, offset);
|
|
665
|
+
offset += 1;
|
|
666
|
+
for (const p of params.points) {
|
|
667
|
+
data.writeBigUInt64LE(p.xIn, offset);
|
|
668
|
+
offset += 8;
|
|
669
|
+
data.writeBigUInt64LE(toQ32(p.priceFactor), offset);
|
|
670
|
+
offset += 8;
|
|
671
|
+
data.writeUInt8(
|
|
672
|
+
interpolationToByte(p.interpolation ?? params.defaultInterpolation),
|
|
673
|
+
offset
|
|
674
|
+
);
|
|
675
|
+
offset += 1;
|
|
676
|
+
const params_ = p.params ?? new Uint8Array(4);
|
|
677
|
+
Buffer.from(params_).copy(data, offset, 0, 4);
|
|
678
|
+
offset += 4;
|
|
679
|
+
}
|
|
680
|
+
return new TransactionInstruction5({
|
|
681
|
+
programId,
|
|
682
|
+
keys: [
|
|
683
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
684
|
+
{ pubkey: curveMetaPda, isSigner: false, isWritable: true },
|
|
685
|
+
{ pubkey: curvePrefabsPda, isSigner: false, isWritable: true }
|
|
686
|
+
],
|
|
687
|
+
data
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
function buildSetRiskCurve(authority, curveMetaPda, curvePrefabsPda, params, programId = HADRON_PROGRAM_ID) {
|
|
691
|
+
const slot = params.slot ?? 0;
|
|
692
|
+
const xMode = params.xMode ?? 0 /* Native */;
|
|
693
|
+
const riskMode = params.riskMode ?? 0 /* Virtual */;
|
|
694
|
+
const numPoints = params.points.length;
|
|
695
|
+
const data = Buffer.alloc(
|
|
696
|
+
1 + 1 + 1 + 1 + 1 + 1 + 1 + numPoints * POINT_DATA_SIZE
|
|
697
|
+
);
|
|
698
|
+
let offset = 0;
|
|
699
|
+
data.writeUInt8(Discriminator.SetRiskCurve, offset);
|
|
700
|
+
offset += 1;
|
|
701
|
+
data.writeUInt8(slot, offset);
|
|
702
|
+
offset += 1;
|
|
703
|
+
data.writeUInt8(params.side, offset);
|
|
704
|
+
offset += 1;
|
|
705
|
+
data.writeUInt8(interpolationToByte(params.defaultInterpolation), offset);
|
|
706
|
+
offset += 1;
|
|
707
|
+
data.writeUInt8(numPoints, offset);
|
|
708
|
+
offset += 1;
|
|
709
|
+
data.writeUInt8(xMode, offset);
|
|
710
|
+
offset += 1;
|
|
711
|
+
data.writeUInt8(riskMode, offset);
|
|
712
|
+
offset += 1;
|
|
713
|
+
for (const p of params.points) {
|
|
714
|
+
data.writeBigUInt64LE(toQ32(p.pctBase), offset);
|
|
715
|
+
offset += 8;
|
|
716
|
+
data.writeBigUInt64LE(toQ32(p.priceFactor), offset);
|
|
717
|
+
offset += 8;
|
|
718
|
+
data.writeUInt8(
|
|
719
|
+
interpolationToByte(p.interpolation ?? params.defaultInterpolation),
|
|
720
|
+
offset
|
|
721
|
+
);
|
|
722
|
+
offset += 1;
|
|
723
|
+
const params_ = p.params ?? new Uint8Array(4);
|
|
724
|
+
Buffer.from(params_).copy(data, offset, 0, 4);
|
|
725
|
+
offset += 4;
|
|
726
|
+
}
|
|
727
|
+
return new TransactionInstruction5({
|
|
728
|
+
programId,
|
|
729
|
+
keys: [
|
|
730
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
731
|
+
{ pubkey: curveMetaPda, isSigner: false, isWritable: true },
|
|
732
|
+
{ pubkey: curvePrefabsPda, isSigner: false, isWritable: true }
|
|
733
|
+
],
|
|
734
|
+
data
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
function buildSetRiskCurveAbsolute(authority, curveMetaPda, curvePrefabsPda, params, programId = HADRON_PROGRAM_ID) {
|
|
738
|
+
const slot = params.slot ?? 0;
|
|
739
|
+
const riskMode = params.riskMode ?? 0 /* Virtual */;
|
|
740
|
+
const numPoints = params.points.length;
|
|
741
|
+
const data = Buffer.alloc(
|
|
742
|
+
1 + 1 + 1 + 1 + 1 + 1 + 1 + numPoints * POINT_DATA_SIZE
|
|
743
|
+
);
|
|
744
|
+
let offset = 0;
|
|
745
|
+
data.writeUInt8(Discriminator.SetRiskCurve, offset);
|
|
746
|
+
offset += 1;
|
|
747
|
+
data.writeUInt8(slot, offset);
|
|
748
|
+
offset += 1;
|
|
749
|
+
data.writeUInt8(params.side, offset);
|
|
750
|
+
offset += 1;
|
|
751
|
+
data.writeUInt8(interpolationToByte(params.defaultInterpolation), offset);
|
|
752
|
+
offset += 1;
|
|
753
|
+
data.writeUInt8(numPoints, offset);
|
|
754
|
+
offset += 1;
|
|
755
|
+
data.writeUInt8(1 /* Alternate */, offset);
|
|
756
|
+
offset += 1;
|
|
757
|
+
data.writeUInt8(riskMode, offset);
|
|
758
|
+
offset += 1;
|
|
759
|
+
for (const p of params.points) {
|
|
760
|
+
data.writeBigUInt64LE(p.vaultBalance, offset);
|
|
761
|
+
offset += 8;
|
|
762
|
+
data.writeBigUInt64LE(toQ32(p.priceFactor), offset);
|
|
763
|
+
offset += 8;
|
|
764
|
+
data.writeUInt8(
|
|
765
|
+
interpolationToByte(p.interpolation ?? params.defaultInterpolation),
|
|
766
|
+
offset
|
|
767
|
+
);
|
|
768
|
+
offset += 1;
|
|
769
|
+
const params_ = p.params ?? new Uint8Array(4);
|
|
770
|
+
Buffer.from(params_).copy(data, offset, 0, 4);
|
|
771
|
+
offset += 4;
|
|
772
|
+
}
|
|
773
|
+
return new TransactionInstruction5({
|
|
774
|
+
programId,
|
|
775
|
+
keys: [
|
|
776
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
777
|
+
{ pubkey: curveMetaPda, isSigner: false, isWritable: true },
|
|
778
|
+
{ pubkey: curvePrefabsPda, isSigner: false, isWritable: true }
|
|
779
|
+
],
|
|
780
|
+
data
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
function buildSetCurveBoth(authority, curveMetaPda, curvePrefabsPda, params, programId = HADRON_PROGRAM_ID) {
|
|
784
|
+
const bidIx = buildSetCurve(authority, curveMetaPda, curvePrefabsPda, { ...params.bid, side: 0 /* Bid */ }, programId);
|
|
785
|
+
const askIx = buildSetCurve(authority, curveMetaPda, curvePrefabsPda, { ...params.ask, side: 1 /* Ask */ }, programId);
|
|
786
|
+
return [bidIx, askIx];
|
|
787
|
+
}
|
|
788
|
+
function buildSetRiskCurveBoth(authority, curveMetaPda, curvePrefabsPda, params, programId = HADRON_PROGRAM_ID) {
|
|
789
|
+
const bidIx = buildSetRiskCurve(authority, curveMetaPda, curvePrefabsPda, { ...params.bid, side: 0 /* Bid */ }, programId);
|
|
790
|
+
const askIx = buildSetRiskCurve(authority, curveMetaPda, curvePrefabsPda, { ...params.ask, side: 1 /* Ask */ }, programId);
|
|
791
|
+
return [bidIx, askIx];
|
|
792
|
+
}
|
|
793
|
+
function buildSetRiskCurveAbsoluteBoth(authority, curveMetaPda, curvePrefabsPda, params, programId = HADRON_PROGRAM_ID) {
|
|
794
|
+
const bidIx = buildSetRiskCurveAbsolute(authority, curveMetaPda, curvePrefabsPda, { ...params.bid, side: 0 /* Bid */ }, programId);
|
|
795
|
+
const askIx = buildSetRiskCurveAbsolute(authority, curveMetaPda, curvePrefabsPda, { ...params.ask, side: 1 /* Ask */ }, programId);
|
|
796
|
+
return [bidIx, askIx];
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
// src/instructions/oracle.ts
|
|
800
|
+
import {
|
|
801
|
+
SYSVAR_CLOCK_PUBKEY as SYSVAR_CLOCK_PUBKEY2,
|
|
802
|
+
TransactionInstruction as TransactionInstruction6
|
|
803
|
+
} from "@solana/web3.js";
|
|
804
|
+
function buildUpdateMidprice(authority, midpriceOraclePda, params, programId = HADRON_PROGRAM_ID) {
|
|
805
|
+
const data = Buffer.alloc(1 + 8 + 8);
|
|
806
|
+
data.writeUInt8(Discriminator.UpdateMidprice, 0);
|
|
807
|
+
data.writeBigUInt64LE(params.sequence ?? 0n, 1);
|
|
808
|
+
data.writeBigUInt64LE(params.midpriceQ32, 9);
|
|
809
|
+
return new TransactionInstruction6({
|
|
810
|
+
programId,
|
|
811
|
+
keys: [
|
|
812
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
813
|
+
{ pubkey: midpriceOraclePda, isSigner: false, isWritable: true },
|
|
814
|
+
{ pubkey: SYSVAR_CLOCK_PUBKEY2, isSigner: false, isWritable: false }
|
|
815
|
+
],
|
|
816
|
+
data
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
function buildUpdateBaseSpread(authority, midpriceOraclePda, params, programId = HADRON_PROGRAM_ID) {
|
|
820
|
+
const data = Buffer.alloc(1 + 8 + 8);
|
|
821
|
+
data.writeUInt8(Discriminator.UpdateBaseSpread, 0);
|
|
822
|
+
data.writeBigUInt64LE(params.sequence ?? 0n, 1);
|
|
823
|
+
data.writeBigUInt64LE(params.baseSpreadQ32, 9);
|
|
824
|
+
return new TransactionInstruction6({
|
|
825
|
+
programId,
|
|
826
|
+
keys: [
|
|
827
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
828
|
+
{ pubkey: midpriceOraclePda, isSigner: false, isWritable: true },
|
|
829
|
+
{ pubkey: SYSVAR_CLOCK_PUBKEY2, isSigner: false, isWritable: false }
|
|
830
|
+
],
|
|
831
|
+
data
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
function buildUpdateMidpriceAndBaseSpread(authority, midpriceOraclePda, params, programId = HADRON_PROGRAM_ID) {
|
|
835
|
+
const data = Buffer.alloc(1 + 8 + 8 + 8);
|
|
836
|
+
data.writeUInt8(Discriminator.UpdateMidpriceAndBaseSpread, 0);
|
|
837
|
+
data.writeBigUInt64LE(params.sequence ?? 0n, 1);
|
|
838
|
+
data.writeBigUInt64LE(params.midpriceQ32, 9);
|
|
839
|
+
data.writeBigUInt64LE(params.baseSpreadQ32, 17);
|
|
840
|
+
return new TransactionInstruction6({
|
|
841
|
+
programId,
|
|
842
|
+
keys: [
|
|
843
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
844
|
+
{ pubkey: midpriceOraclePda, isSigner: false, isWritable: true },
|
|
845
|
+
{ pubkey: SYSVAR_CLOCK_PUBKEY2, isSigner: false, isWritable: false }
|
|
846
|
+
],
|
|
847
|
+
data
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
// src/instructions/switchCurve.ts
|
|
852
|
+
import { TransactionInstruction as TransactionInstruction7 } from "@solana/web3.js";
|
|
853
|
+
function buildSwitchPriceCurve(authority, curveMetaPda, params, programId = HADRON_PROGRAM_ID) {
|
|
854
|
+
const data = Buffer.alloc(1 + 1 + 1);
|
|
855
|
+
data.writeUInt8(Discriminator.SwitchPriceCurve, 0);
|
|
856
|
+
data.writeUInt8(params.side, 1);
|
|
857
|
+
data.writeUInt8(params.slot, 2);
|
|
858
|
+
return new TransactionInstruction7({
|
|
859
|
+
programId,
|
|
860
|
+
keys: [
|
|
861
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
862
|
+
{ pubkey: curveMetaPda, isSigner: false, isWritable: true }
|
|
863
|
+
],
|
|
864
|
+
data
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
function buildSwitchRiskCurve(authority, curveMetaPda, params, programId = HADRON_PROGRAM_ID) {
|
|
868
|
+
const data = Buffer.alloc(1 + 1 + 1);
|
|
869
|
+
data.writeUInt8(Discriminator.SwitchRiskCurve, 0);
|
|
870
|
+
data.writeUInt8(params.side, 1);
|
|
871
|
+
data.writeUInt8(params.slot, 2);
|
|
872
|
+
return new TransactionInstruction7({
|
|
873
|
+
programId,
|
|
874
|
+
keys: [
|
|
875
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
876
|
+
{ pubkey: curveMetaPda, isSigner: false, isWritable: true }
|
|
877
|
+
],
|
|
878
|
+
data
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
// src/instructions/curveUpdates.ts
|
|
883
|
+
import { TransactionInstruction as TransactionInstruction8 } from "@solana/web3.js";
|
|
884
|
+
function buildSubmitCurveUpdates(authority, curveUpdatesPda, ops, programId = HADRON_PROGRAM_ID) {
|
|
885
|
+
const data = Buffer.alloc(1 + 1 + ops.length * CURVE_UPDATE_OP_SIZE);
|
|
886
|
+
let offset = 0;
|
|
887
|
+
data.writeUInt8(Discriminator.SubmitCurveUpdates, offset);
|
|
888
|
+
offset += 1;
|
|
889
|
+
data.writeUInt8(ops.length, offset);
|
|
890
|
+
offset += 1;
|
|
891
|
+
for (const op of ops) {
|
|
892
|
+
data.writeUInt8(op.curveType, offset);
|
|
893
|
+
offset += 1;
|
|
894
|
+
data.writeUInt8(op.opKind, offset);
|
|
895
|
+
offset += 1;
|
|
896
|
+
data.writeUInt8(op.pointIndex, offset);
|
|
897
|
+
offset += 1;
|
|
898
|
+
data.writeUInt8(op.interpolation, offset);
|
|
899
|
+
offset += 1;
|
|
900
|
+
data.writeBigUInt64LE(op.xIn, offset);
|
|
901
|
+
offset += 8;
|
|
902
|
+
data.writeBigUInt64LE(op.priceFactorQ32, offset);
|
|
903
|
+
offset += 8;
|
|
904
|
+
const params = op.params ?? new Uint8Array(4);
|
|
905
|
+
Buffer.from(params).copy(data, offset, 0, 4);
|
|
906
|
+
offset += 4;
|
|
907
|
+
}
|
|
908
|
+
return new TransactionInstruction8({
|
|
909
|
+
programId,
|
|
910
|
+
keys: [
|
|
911
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
912
|
+
{ pubkey: curveUpdatesPda, isSigner: false, isWritable: true }
|
|
913
|
+
],
|
|
914
|
+
data
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
function buildApplyCurveUpdates(authority, curveMetaPda, curvePrefabsPda, curveUpdatesPda, programId = HADRON_PROGRAM_ID) {
|
|
918
|
+
const data = Buffer.alloc(1);
|
|
919
|
+
data.writeUInt8(Discriminator.ApplyCurveUpdates, 0);
|
|
920
|
+
return new TransactionInstruction8({
|
|
921
|
+
programId,
|
|
922
|
+
keys: [
|
|
923
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
924
|
+
{ pubkey: curveMetaPda, isSigner: false, isWritable: false },
|
|
925
|
+
{ pubkey: curvePrefabsPda, isSigner: false, isWritable: true },
|
|
926
|
+
{ pubkey: curveUpdatesPda, isSigner: false, isWritable: true }
|
|
927
|
+
],
|
|
928
|
+
data
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
// src/instructions/authority.ts
|
|
933
|
+
import {
|
|
934
|
+
SYSVAR_CLOCK_PUBKEY as SYSVAR_CLOCK_PUBKEY3,
|
|
935
|
+
TransactionInstruction as TransactionInstruction9
|
|
936
|
+
} from "@solana/web3.js";
|
|
937
|
+
function buildNominateAuthority(authority, configPda, params, programId = HADRON_PROGRAM_ID) {
|
|
938
|
+
const data = Buffer.alloc(1 + 32 + 8);
|
|
939
|
+
let offset = 0;
|
|
940
|
+
data.writeUInt8(Discriminator.NominateAuthority, offset);
|
|
941
|
+
offset += 1;
|
|
942
|
+
params.newAuthority.toBuffer().copy(data, offset);
|
|
943
|
+
offset += 32;
|
|
944
|
+
data.writeBigUInt64LE(params.expirySlot, offset);
|
|
945
|
+
return new TransactionInstruction9({
|
|
946
|
+
programId,
|
|
947
|
+
keys: [
|
|
948
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
949
|
+
{ pubkey: configPda, isSigner: false, isWritable: true },
|
|
950
|
+
{ pubkey: SYSVAR_CLOCK_PUBKEY3, isSigner: false, isWritable: false }
|
|
951
|
+
],
|
|
952
|
+
data
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
function buildAcceptAuthority(newAuthority, configPda, programId = HADRON_PROGRAM_ID) {
|
|
956
|
+
const data = Buffer.alloc(1);
|
|
957
|
+
data.writeUInt8(Discriminator.AcceptAuthority, 0);
|
|
958
|
+
return new TransactionInstruction9({
|
|
959
|
+
programId,
|
|
960
|
+
keys: [
|
|
961
|
+
{ pubkey: newAuthority, isSigner: true, isWritable: false },
|
|
962
|
+
{ pubkey: configPda, isSigner: false, isWritable: true },
|
|
963
|
+
{ pubkey: SYSVAR_CLOCK_PUBKEY3, isSigner: false, isWritable: false }
|
|
964
|
+
],
|
|
965
|
+
data
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
function buildSetQuotingAuthority(authority, configPda, oraclePda, curveMetaPda, curveUpdatesPda, params, programId = HADRON_PROGRAM_ID) {
|
|
969
|
+
const data = Buffer.alloc(1 + 32);
|
|
970
|
+
data.writeUInt8(Discriminator.SetQuotingAuthority, 0);
|
|
971
|
+
params.newQuotingAuthority.toBuffer().copy(data, 1);
|
|
972
|
+
const keys = [
|
|
973
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
974
|
+
{ pubkey: configPda, isSigner: false, isWritable: false },
|
|
975
|
+
{ pubkey: oraclePda, isSigner: false, isWritable: true },
|
|
976
|
+
{ pubkey: curveMetaPda, isSigner: false, isWritable: true },
|
|
977
|
+
{ pubkey: curveUpdatesPda, isSigner: false, isWritable: true }
|
|
978
|
+
];
|
|
979
|
+
if (params.spreadConfigPda) {
|
|
980
|
+
keys.push({
|
|
981
|
+
pubkey: params.spreadConfigPda,
|
|
982
|
+
isSigner: false,
|
|
983
|
+
isWritable: true
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
return new TransactionInstruction9({
|
|
987
|
+
programId,
|
|
988
|
+
keys,
|
|
989
|
+
data
|
|
990
|
+
});
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
// src/instructions/feeConfig.ts
|
|
994
|
+
import {
|
|
995
|
+
SystemProgram as SystemProgram2,
|
|
996
|
+
TransactionInstruction as TransactionInstruction10
|
|
997
|
+
} from "@solana/web3.js";
|
|
998
|
+
function buildInitializeFeeConfig(payer, authority, params, programId = HADRON_PROGRAM_ID) {
|
|
999
|
+
const [feeConfigPda] = getFeeConfigAddress(programId);
|
|
1000
|
+
const data = Buffer.alloc(1 + 4 + 32 + 32);
|
|
1001
|
+
let offset = 0;
|
|
1002
|
+
data.writeUInt8(Discriminator.InitializeFeeConfig, offset);
|
|
1003
|
+
offset += 1;
|
|
1004
|
+
data.writeUInt32LE(params.feePpm, offset);
|
|
1005
|
+
offset += 4;
|
|
1006
|
+
params.feeAdmin.toBuffer().copy(data, offset);
|
|
1007
|
+
offset += 32;
|
|
1008
|
+
params.feeRecipient.toBuffer().copy(data, offset);
|
|
1009
|
+
return new TransactionInstruction10({
|
|
1010
|
+
programId,
|
|
1011
|
+
keys: [
|
|
1012
|
+
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
1013
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
1014
|
+
{ pubkey: feeConfigPda, isSigner: false, isWritable: true },
|
|
1015
|
+
{ pubkey: SystemProgram2.programId, isSigner: false, isWritable: false }
|
|
1016
|
+
],
|
|
1017
|
+
data
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
function buildUpdateFeeConfig(feeAdmin, params, programId = HADRON_PROGRAM_ID) {
|
|
1021
|
+
const [feeConfigPda] = getFeeConfigAddress(programId);
|
|
1022
|
+
const data = Buffer.alloc(1 + 4 + 32);
|
|
1023
|
+
let offset = 0;
|
|
1024
|
+
data.writeUInt8(Discriminator.UpdateFeeConfig, offset);
|
|
1025
|
+
offset += 1;
|
|
1026
|
+
data.writeUInt32LE(params.feePpm !== null ? params.feePpm : 4294967295, offset);
|
|
1027
|
+
offset += 4;
|
|
1028
|
+
if (params.feeRecipient) {
|
|
1029
|
+
params.feeRecipient.toBuffer().copy(data, offset);
|
|
1030
|
+
}
|
|
1031
|
+
return new TransactionInstruction10({
|
|
1032
|
+
programId,
|
|
1033
|
+
keys: [
|
|
1034
|
+
{ pubkey: feeAdmin, isSigner: true, isWritable: false },
|
|
1035
|
+
{ pubkey: feeConfigPda, isSigner: false, isWritable: true }
|
|
1036
|
+
],
|
|
1037
|
+
data
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
function buildRotateFeeAdmin(feeAdmin, params, programId = HADRON_PROGRAM_ID) {
|
|
1041
|
+
const [feeConfigPda] = getFeeConfigAddress(programId);
|
|
1042
|
+
const data = Buffer.alloc(1 + 32);
|
|
1043
|
+
data.writeUInt8(Discriminator.RotateFeeAdmin, 0);
|
|
1044
|
+
params.newFeeAdmin.toBuffer().copy(data, 1);
|
|
1045
|
+
return new TransactionInstruction10({
|
|
1046
|
+
programId,
|
|
1047
|
+
keys: [
|
|
1048
|
+
{ pubkey: feeAdmin, isSigner: true, isWritable: false },
|
|
1049
|
+
{ pubkey: feeConfigPda, isSigner: false, isWritable: true }
|
|
1050
|
+
],
|
|
1051
|
+
data
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
// src/instructions/spreadConfig.ts
|
|
1056
|
+
import {
|
|
1057
|
+
SystemProgram as SystemProgram3,
|
|
1058
|
+
TransactionInstruction as TransactionInstruction11
|
|
1059
|
+
} from "@solana/web3.js";
|
|
1060
|
+
function buildInitializeSpreadConfig(payer, authority, configPda, params, programId = HADRON_PROGRAM_ID) {
|
|
1061
|
+
const [spreadConfigPda] = getSpreadConfigAddress(configPda, programId);
|
|
1062
|
+
const data = Buffer.alloc(1 + 32);
|
|
1063
|
+
data.writeUInt8(Discriminator.InitializeSpreadConfig, 0);
|
|
1064
|
+
params.admin.toBuffer().copy(data, 1);
|
|
1065
|
+
return new TransactionInstruction11({
|
|
1066
|
+
programId,
|
|
1067
|
+
keys: [
|
|
1068
|
+
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
1069
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
1070
|
+
{ pubkey: configPda, isSigner: false, isWritable: true },
|
|
1071
|
+
{ pubkey: spreadConfigPda, isSigner: false, isWritable: true },
|
|
1072
|
+
{ pubkey: SystemProgram3.programId, isSigner: false, isWritable: false }
|
|
1073
|
+
],
|
|
1074
|
+
data
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
function buildUpdateSpreadConfig(admin, configPda, params, programId = HADRON_PROGRAM_ID) {
|
|
1078
|
+
const [spreadConfigPda] = getSpreadConfigAddress(configPda, programId);
|
|
1079
|
+
const numTriggers = params.triggers.length;
|
|
1080
|
+
const data = Buffer.alloc(1 + 1 + numTriggers * 34);
|
|
1081
|
+
let offset = 0;
|
|
1082
|
+
data.writeUInt8(Discriminator.UpdateSpreadConfig, offset);
|
|
1083
|
+
offset += 1;
|
|
1084
|
+
data.writeUInt8(numTriggers, offset);
|
|
1085
|
+
offset += 1;
|
|
1086
|
+
for (const t of params.triggers) {
|
|
1087
|
+
t.account.toBuffer().copy(data, offset);
|
|
1088
|
+
offset += 32;
|
|
1089
|
+
data.writeUInt16LE(t.spreadBps, offset);
|
|
1090
|
+
offset += 2;
|
|
1091
|
+
}
|
|
1092
|
+
return new TransactionInstruction11({
|
|
1093
|
+
programId,
|
|
1094
|
+
keys: [
|
|
1095
|
+
{ pubkey: admin, isSigner: true, isWritable: false },
|
|
1096
|
+
{ pubkey: configPda, isSigner: false, isWritable: false },
|
|
1097
|
+
{ pubkey: spreadConfigPda, isSigner: false, isWritable: true }
|
|
1098
|
+
],
|
|
1099
|
+
data
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
// src/instructions/poolState.ts
|
|
1104
|
+
import {
|
|
1105
|
+
TransactionInstruction as TransactionInstruction12
|
|
1106
|
+
} from "@solana/web3.js";
|
|
1107
|
+
function buildSetPoolState(authority, configPda, params, programId = HADRON_PROGRAM_ID) {
|
|
1108
|
+
const data = Buffer.alloc(1 + 1);
|
|
1109
|
+
data.writeUInt8(Discriminator.SetPoolState, 0);
|
|
1110
|
+
data.writeUInt8(params.newState, 1);
|
|
1111
|
+
return new TransactionInstruction12({
|
|
1112
|
+
programId,
|
|
1113
|
+
keys: [
|
|
1114
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
1115
|
+
{ pubkey: configPda, isSigner: false, isWritable: true }
|
|
1116
|
+
],
|
|
1117
|
+
data
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
function buildUpdateDeltaStaleness(authority, configPda, params, programId = HADRON_PROGRAM_ID) {
|
|
1121
|
+
const data = Buffer.alloc(1 + 1);
|
|
1122
|
+
data.writeUInt8(Discriminator.UpdateDeltaStaleness, 0);
|
|
1123
|
+
data.writeUInt8(params.deltaStaleness, 1);
|
|
1124
|
+
return new TransactionInstruction12({
|
|
1125
|
+
programId,
|
|
1126
|
+
keys: [
|
|
1127
|
+
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
1128
|
+
{ pubkey: configPda, isSigner: false, isWritable: true }
|
|
1129
|
+
],
|
|
1130
|
+
data
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
function buildClosePool(authority, configPda, midpriceOraclePda, curveMetaPda, curvePrefabsPda, curveUpdatesPda, vaultX, vaultY, tokenProgramX, tokenProgramY, spreadConfigInitialized = false, programId = HADRON_PROGRAM_ID) {
|
|
1134
|
+
const data = Buffer.alloc(1);
|
|
1135
|
+
data.writeUInt8(Discriminator.ClosePool, 0);
|
|
1136
|
+
const keys = [
|
|
1137
|
+
{ pubkey: authority, isSigner: true, isWritable: true },
|
|
1138
|
+
{ pubkey: configPda, isSigner: false, isWritable: true },
|
|
1139
|
+
{ pubkey: midpriceOraclePda, isSigner: false, isWritable: true },
|
|
1140
|
+
{ pubkey: curveMetaPda, isSigner: false, isWritable: true },
|
|
1141
|
+
{ pubkey: curvePrefabsPda, isSigner: false, isWritable: true },
|
|
1142
|
+
{ pubkey: curveUpdatesPda, isSigner: false, isWritable: true },
|
|
1143
|
+
{ pubkey: vaultX, isSigner: false, isWritable: true },
|
|
1144
|
+
{ pubkey: vaultY, isSigner: false, isWritable: true },
|
|
1145
|
+
{ pubkey: tokenProgramX, isSigner: false, isWritable: false },
|
|
1146
|
+
{ pubkey: tokenProgramY, isSigner: false, isWritable: false }
|
|
1147
|
+
];
|
|
1148
|
+
if (spreadConfigInitialized) {
|
|
1149
|
+
const [spreadConfigPda] = getSpreadConfigAddress(configPda, programId);
|
|
1150
|
+
keys.push({
|
|
1151
|
+
pubkey: spreadConfigPda,
|
|
1152
|
+
isSigner: false,
|
|
1153
|
+
isWritable: true
|
|
1154
|
+
});
|
|
1155
|
+
}
|
|
1156
|
+
return new TransactionInstruction12({ programId, keys, data });
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
// src/hadron.ts
|
|
1160
|
+
var Hadron = class _Hadron {
|
|
1161
|
+
constructor(connection, poolAddress, addresses, config, oracle, curveMeta, curvePrefabsData, programId = HADRON_PROGRAM_ID) {
|
|
1162
|
+
this.connection = connection;
|
|
1163
|
+
this.poolAddress = poolAddress;
|
|
1164
|
+
this.addresses = addresses;
|
|
1165
|
+
this.config = config;
|
|
1166
|
+
this.oracle = oracle;
|
|
1167
|
+
this.curveMeta = curveMeta;
|
|
1168
|
+
this.curvePrefabsData = curvePrefabsData;
|
|
1169
|
+
this.programId = programId;
|
|
1170
|
+
}
|
|
1171
|
+
// ==========================================================================
|
|
1172
|
+
// Static Factory Methods
|
|
1173
|
+
// ==========================================================================
|
|
1174
|
+
/**
|
|
1175
|
+
* Load a Hadron instance from an existing pool address.
|
|
1176
|
+
* Fetches all required accounts from the chain.
|
|
1177
|
+
*/
|
|
1178
|
+
static async load(connection, poolAddress) {
|
|
1179
|
+
const programId = HADRON_PROGRAM_ID;
|
|
1180
|
+
const configInfo = await connection.getAccountInfo(poolAddress);
|
|
1181
|
+
if (!configInfo) throw new Error("Config account not found");
|
|
1182
|
+
const config = decodeConfig(configInfo.data);
|
|
1183
|
+
const tokenProgramX = config.tokenProgramX;
|
|
1184
|
+
const tokenProgramY = config.tokenProgramY;
|
|
1185
|
+
const addresses = derivePoolAddresses(
|
|
1186
|
+
config.seed,
|
|
1187
|
+
config.mintX,
|
|
1188
|
+
config.mintY,
|
|
1189
|
+
tokenProgramX,
|
|
1190
|
+
tokenProgramY,
|
|
1191
|
+
programId
|
|
1192
|
+
);
|
|
1193
|
+
const [oracleInfo, curveMetaInfo, curvePrefabsInfo] = await Promise.all([
|
|
1194
|
+
connection.getAccountInfo(addresses.midpriceOracle),
|
|
1195
|
+
connection.getAccountInfo(addresses.curveMeta),
|
|
1196
|
+
connection.getAccountInfo(addresses.curvePrefabs)
|
|
1197
|
+
]);
|
|
1198
|
+
if (!oracleInfo) throw new Error("MidpriceOracle account not found");
|
|
1199
|
+
if (!curveMetaInfo) throw new Error("CurveMeta account not found");
|
|
1200
|
+
if (!curvePrefabsInfo) throw new Error("CurvePrefabs account not found");
|
|
1201
|
+
const oracle = decodeMidpriceOracle(oracleInfo.data);
|
|
1202
|
+
const curveMeta = decodeCurveMeta(curveMetaInfo.data);
|
|
1203
|
+
return new _Hadron(
|
|
1204
|
+
connection,
|
|
1205
|
+
poolAddress,
|
|
1206
|
+
addresses,
|
|
1207
|
+
config,
|
|
1208
|
+
oracle,
|
|
1209
|
+
curveMeta,
|
|
1210
|
+
curvePrefabsInfo.data,
|
|
1211
|
+
programId
|
|
1212
|
+
);
|
|
1213
|
+
}
|
|
1214
|
+
/**
|
|
1215
|
+
* Load a Hadron instance from pool identity (seed + mints).
|
|
1216
|
+
*/
|
|
1217
|
+
static async loadFromSeed(connection, seed, mintX, mintY) {
|
|
1218
|
+
const programId = HADRON_PROGRAM_ID;
|
|
1219
|
+
const [poolAddress] = getConfigAddress(seed, mintX, mintY, programId);
|
|
1220
|
+
return _Hadron.load(connection, poolAddress);
|
|
1221
|
+
}
|
|
1222
|
+
/**
|
|
1223
|
+
* Build all instructions needed to initialize a new pool.
|
|
1224
|
+
*
|
|
1225
|
+
* Returns the allocate + initialize instructions and the derived pool address.
|
|
1226
|
+
* The caller is responsible for grouping them into transactions and sending.
|
|
1227
|
+
* The allocate instruction(s) must be confirmed before the initialize instruction.
|
|
1228
|
+
*
|
|
1229
|
+
* After the pool is live on-chain, load it with `Hadron.load(connection, poolAddress)`.
|
|
1230
|
+
*
|
|
1231
|
+
* ```ts
|
|
1232
|
+
* const { instructions, poolAddress, seed } = Hadron.initialize(payer, {
|
|
1233
|
+
* mintX,
|
|
1234
|
+
* mintY,
|
|
1235
|
+
* authority: payer,
|
|
1236
|
+
* initialMidpriceQ32: Q32_ONE,
|
|
1237
|
+
* });
|
|
1238
|
+
* ```
|
|
1239
|
+
*/
|
|
1240
|
+
static initialize(payer, params) {
|
|
1241
|
+
const programId = HADRON_PROGRAM_ID;
|
|
1242
|
+
const seed = params.seed ?? _Hadron.randomSeed();
|
|
1243
|
+
const maxPrefabSlots = params.maxPrefabSlots ?? DEFAULT_MAX_PREFAB_SLOTS;
|
|
1244
|
+
const maxCurvePoints = params.maxCurvePoints ?? DEFAULT_MAX_CURVE_POINTS;
|
|
1245
|
+
const resolvedParams = { ...params, seed };
|
|
1246
|
+
const [poolAddress] = getConfigAddress(
|
|
1247
|
+
seed,
|
|
1248
|
+
params.mintX,
|
|
1249
|
+
params.mintY,
|
|
1250
|
+
programId
|
|
1251
|
+
);
|
|
1252
|
+
const allocateParams = {
|
|
1253
|
+
seed,
|
|
1254
|
+
mintX: params.mintX,
|
|
1255
|
+
mintY: params.mintY,
|
|
1256
|
+
maxPrefabSlots,
|
|
1257
|
+
maxCurvePoints
|
|
1258
|
+
};
|
|
1259
|
+
const instructions = [];
|
|
1260
|
+
const size = curvePrefabsSize(maxPrefabSlots, maxCurvePoints);
|
|
1261
|
+
const allocateCalls = size > 10240 ? 2 : 1;
|
|
1262
|
+
for (let i = 0; i < allocateCalls; i++) {
|
|
1263
|
+
instructions.push(buildAllocateCurvePrefabs(payer, allocateParams, programId));
|
|
1264
|
+
}
|
|
1265
|
+
instructions.push(buildInitialize(payer, resolvedParams, programId));
|
|
1266
|
+
return { instructions, poolAddress, seed };
|
|
1267
|
+
}
|
|
1268
|
+
/** Generate a random u64 seed. */
|
|
1269
|
+
static randomSeed() {
|
|
1270
|
+
const buf = new Uint8Array(8);
|
|
1271
|
+
crypto.getRandomValues(buf);
|
|
1272
|
+
return new DataView(buf.buffer).getBigUint64(0, true);
|
|
1273
|
+
}
|
|
1274
|
+
// ==========================================================================
|
|
1275
|
+
// State Queries
|
|
1276
|
+
// ==========================================================================
|
|
1277
|
+
/** Re-fetch all account state from the chain. */
|
|
1278
|
+
async refetchStates() {
|
|
1279
|
+
const [configInfo, oracleInfo, curveMetaInfo, curvePrefabsInfo] = await Promise.all([
|
|
1280
|
+
this.connection.getAccountInfo(this.poolAddress),
|
|
1281
|
+
this.connection.getAccountInfo(this.addresses.midpriceOracle),
|
|
1282
|
+
this.connection.getAccountInfo(this.addresses.curveMeta),
|
|
1283
|
+
this.connection.getAccountInfo(this.addresses.curvePrefabs)
|
|
1284
|
+
]);
|
|
1285
|
+
if (configInfo) this.config = decodeConfig(configInfo.data);
|
|
1286
|
+
if (oracleInfo) this.oracle = decodeMidpriceOracle(oracleInfo.data);
|
|
1287
|
+
if (curveMetaInfo) this.curveMeta = decodeCurveMeta(curveMetaInfo.data);
|
|
1288
|
+
if (curvePrefabsInfo) this.curvePrefabsData = curvePrefabsInfo.data;
|
|
1289
|
+
}
|
|
1290
|
+
/** Get midprice as a floating-point number. */
|
|
1291
|
+
getMidprice() {
|
|
1292
|
+
return fromQ32(this.oracle.midpriceQ32);
|
|
1293
|
+
}
|
|
1294
|
+
/** Get base spread as a floating-point number. */
|
|
1295
|
+
getBaseSpread() {
|
|
1296
|
+
return fromQ32(this.oracle.baseSpreadQ32);
|
|
1297
|
+
}
|
|
1298
|
+
/** Get the currently active curve slot indices. */
|
|
1299
|
+
getActiveCurveSlots() {
|
|
1300
|
+
return {
|
|
1301
|
+
priceBid: this.curveMeta.activePriceBidSlot,
|
|
1302
|
+
priceAsk: this.curveMeta.activePriceAskSlot,
|
|
1303
|
+
riskBid: this.curveMeta.activeRiskBidSlot,
|
|
1304
|
+
riskAsk: this.curveMeta.activeRiskAskSlot
|
|
1305
|
+
};
|
|
1306
|
+
}
|
|
1307
|
+
/** Decode the currently active curves from prefabs data. */
|
|
1308
|
+
getActiveCurves() {
|
|
1309
|
+
return decodeActiveCurves(this.curvePrefabsData, this.curveMeta);
|
|
1310
|
+
}
|
|
1311
|
+
/** Decode a specific curve slot. */
|
|
1312
|
+
getCurveSlot(curveType, slot) {
|
|
1313
|
+
return decodeCurveSide(
|
|
1314
|
+
this.curvePrefabsData,
|
|
1315
|
+
curveType,
|
|
1316
|
+
slot,
|
|
1317
|
+
this.curveMeta.maxPrefabSlots,
|
|
1318
|
+
this.curveMeta.maxCurvePoints
|
|
1319
|
+
);
|
|
1320
|
+
}
|
|
1321
|
+
// ==========================================================================
|
|
1322
|
+
// Instruction Builders (convenience wrappers)
|
|
1323
|
+
// ==========================================================================
|
|
1324
|
+
/** Build deposit instruction. */
|
|
1325
|
+
deposit(user, params) {
|
|
1326
|
+
return buildDeposit(
|
|
1327
|
+
user,
|
|
1328
|
+
this.poolAddress,
|
|
1329
|
+
this.config.mintX,
|
|
1330
|
+
this.config.mintY,
|
|
1331
|
+
this.config.tokenProgramX,
|
|
1332
|
+
this.config.tokenProgramY,
|
|
1333
|
+
params,
|
|
1334
|
+
this.programId
|
|
1335
|
+
);
|
|
1336
|
+
}
|
|
1337
|
+
/** Build withdraw instruction. */
|
|
1338
|
+
withdraw(user, params) {
|
|
1339
|
+
return buildWithdraw(
|
|
1340
|
+
user,
|
|
1341
|
+
this.poolAddress,
|
|
1342
|
+
this.config.mintX,
|
|
1343
|
+
this.config.mintY,
|
|
1344
|
+
this.config.tokenProgramX,
|
|
1345
|
+
this.config.tokenProgramY,
|
|
1346
|
+
params,
|
|
1347
|
+
this.programId
|
|
1348
|
+
);
|
|
1349
|
+
}
|
|
1350
|
+
/** Build swap instruction. */
|
|
1351
|
+
swap(user, params) {
|
|
1352
|
+
return buildSwapExactIn(
|
|
1353
|
+
user,
|
|
1354
|
+
this.addresses,
|
|
1355
|
+
this.config.mintX,
|
|
1356
|
+
this.config.mintY,
|
|
1357
|
+
this.config.tokenProgramX,
|
|
1358
|
+
this.config.tokenProgramY,
|
|
1359
|
+
params,
|
|
1360
|
+
this.programId
|
|
1361
|
+
);
|
|
1362
|
+
}
|
|
1363
|
+
/** Build set curve instruction. */
|
|
1364
|
+
setCurve(authority, params) {
|
|
1365
|
+
return buildSetCurve(
|
|
1366
|
+
authority,
|
|
1367
|
+
this.addresses.curveMeta,
|
|
1368
|
+
this.addresses.curvePrefabs,
|
|
1369
|
+
params,
|
|
1370
|
+
this.programId
|
|
1371
|
+
);
|
|
1372
|
+
}
|
|
1373
|
+
/** Build set risk curve instruction (percent-based x-axis). */
|
|
1374
|
+
setRiskCurve(authority, params) {
|
|
1375
|
+
return buildSetRiskCurve(
|
|
1376
|
+
authority,
|
|
1377
|
+
this.addresses.curveMeta,
|
|
1378
|
+
this.addresses.curvePrefabs,
|
|
1379
|
+
params,
|
|
1380
|
+
this.programId
|
|
1381
|
+
);
|
|
1382
|
+
}
|
|
1383
|
+
/** Build set risk curve instruction (absolute x-axis). */
|
|
1384
|
+
setRiskCurveAbsolute(authority, params) {
|
|
1385
|
+
return buildSetRiskCurveAbsolute(
|
|
1386
|
+
authority,
|
|
1387
|
+
this.addresses.curveMeta,
|
|
1388
|
+
this.addresses.curvePrefabs,
|
|
1389
|
+
params,
|
|
1390
|
+
this.programId
|
|
1391
|
+
);
|
|
1392
|
+
}
|
|
1393
|
+
/** Build set curve instructions for both bid and ask. Returns [bidIx, askIx]. */
|
|
1394
|
+
setCurveBoth(authority, params) {
|
|
1395
|
+
return buildSetCurveBoth(
|
|
1396
|
+
authority,
|
|
1397
|
+
this.addresses.curveMeta,
|
|
1398
|
+
this.addresses.curvePrefabs,
|
|
1399
|
+
params,
|
|
1400
|
+
this.programId
|
|
1401
|
+
);
|
|
1402
|
+
}
|
|
1403
|
+
/** Build set risk curve instructions for both bid and ask. Returns [bidIx, askIx]. */
|
|
1404
|
+
setRiskCurveBoth(authority, params) {
|
|
1405
|
+
return buildSetRiskCurveBoth(
|
|
1406
|
+
authority,
|
|
1407
|
+
this.addresses.curveMeta,
|
|
1408
|
+
this.addresses.curvePrefabs,
|
|
1409
|
+
params,
|
|
1410
|
+
this.programId
|
|
1411
|
+
);
|
|
1412
|
+
}
|
|
1413
|
+
/** Build set risk curve (absolute x-axis) instructions for both bid and ask. Returns [bidIx, askIx]. */
|
|
1414
|
+
setRiskCurveAbsoluteBoth(authority, params) {
|
|
1415
|
+
return buildSetRiskCurveAbsoluteBoth(
|
|
1416
|
+
authority,
|
|
1417
|
+
this.addresses.curveMeta,
|
|
1418
|
+
this.addresses.curvePrefabs,
|
|
1419
|
+
params,
|
|
1420
|
+
this.programId
|
|
1421
|
+
);
|
|
1422
|
+
}
|
|
1423
|
+
/** Build update midprice instruction. */
|
|
1424
|
+
updateMidprice(authority, params) {
|
|
1425
|
+
return buildUpdateMidprice(
|
|
1426
|
+
authority,
|
|
1427
|
+
this.addresses.midpriceOracle,
|
|
1428
|
+
params,
|
|
1429
|
+
this.programId
|
|
1430
|
+
);
|
|
1431
|
+
}
|
|
1432
|
+
/** Build update base spread instruction. */
|
|
1433
|
+
updateBaseSpread(authority, params) {
|
|
1434
|
+
return buildUpdateBaseSpread(
|
|
1435
|
+
authority,
|
|
1436
|
+
this.addresses.midpriceOracle,
|
|
1437
|
+
params,
|
|
1438
|
+
this.programId
|
|
1439
|
+
);
|
|
1440
|
+
}
|
|
1441
|
+
/** Build atomic update of midprice + base spread. */
|
|
1442
|
+
updateMidpriceAndBaseSpread(authority, params) {
|
|
1443
|
+
return buildUpdateMidpriceAndBaseSpread(
|
|
1444
|
+
authority,
|
|
1445
|
+
this.addresses.midpriceOracle,
|
|
1446
|
+
params,
|
|
1447
|
+
this.programId
|
|
1448
|
+
);
|
|
1449
|
+
}
|
|
1450
|
+
/** Build switch price curve instruction (hot path). */
|
|
1451
|
+
switchPriceCurve(authority, params) {
|
|
1452
|
+
return buildSwitchPriceCurve(
|
|
1453
|
+
authority,
|
|
1454
|
+
this.addresses.curveMeta,
|
|
1455
|
+
params,
|
|
1456
|
+
this.programId
|
|
1457
|
+
);
|
|
1458
|
+
}
|
|
1459
|
+
/** Build switch risk curve instruction (hot path). */
|
|
1460
|
+
switchRiskCurve(authority, params) {
|
|
1461
|
+
return buildSwitchRiskCurve(
|
|
1462
|
+
authority,
|
|
1463
|
+
this.addresses.curveMeta,
|
|
1464
|
+
params,
|
|
1465
|
+
this.programId
|
|
1466
|
+
);
|
|
1467
|
+
}
|
|
1468
|
+
/** Build submit curve updates instruction (hot path). */
|
|
1469
|
+
submitCurveUpdates(authority, ops) {
|
|
1470
|
+
return buildSubmitCurveUpdates(
|
|
1471
|
+
authority,
|
|
1472
|
+
this.addresses.curveUpdates,
|
|
1473
|
+
ops,
|
|
1474
|
+
this.programId
|
|
1475
|
+
);
|
|
1476
|
+
}
|
|
1477
|
+
/** Build apply curve updates instruction. */
|
|
1478
|
+
applyCurveUpdates(authority) {
|
|
1479
|
+
return buildApplyCurveUpdates(
|
|
1480
|
+
authority,
|
|
1481
|
+
this.addresses.curveMeta,
|
|
1482
|
+
this.addresses.curvePrefabs,
|
|
1483
|
+
this.addresses.curveUpdates,
|
|
1484
|
+
this.programId
|
|
1485
|
+
);
|
|
1486
|
+
}
|
|
1487
|
+
/** Build nominate authority instruction. */
|
|
1488
|
+
nominateAuthority(authority, params) {
|
|
1489
|
+
return buildNominateAuthority(
|
|
1490
|
+
authority,
|
|
1491
|
+
this.poolAddress,
|
|
1492
|
+
params,
|
|
1493
|
+
this.programId
|
|
1494
|
+
);
|
|
1495
|
+
}
|
|
1496
|
+
/** Build accept authority instruction. */
|
|
1497
|
+
acceptAuthority(newAuthority) {
|
|
1498
|
+
return buildAcceptAuthority(
|
|
1499
|
+
newAuthority,
|
|
1500
|
+
this.poolAddress,
|
|
1501
|
+
this.programId
|
|
1502
|
+
);
|
|
1503
|
+
}
|
|
1504
|
+
/** Build set pool state instruction. */
|
|
1505
|
+
setPoolState(authority, params) {
|
|
1506
|
+
return buildSetPoolState(
|
|
1507
|
+
authority,
|
|
1508
|
+
this.poolAddress,
|
|
1509
|
+
params,
|
|
1510
|
+
this.programId
|
|
1511
|
+
);
|
|
1512
|
+
}
|
|
1513
|
+
/** Build update delta staleness instruction. */
|
|
1514
|
+
updateDeltaStaleness(authority, params) {
|
|
1515
|
+
return buildUpdateDeltaStaleness(
|
|
1516
|
+
authority,
|
|
1517
|
+
this.poolAddress,
|
|
1518
|
+
params,
|
|
1519
|
+
this.programId
|
|
1520
|
+
);
|
|
1521
|
+
}
|
|
1522
|
+
/** Build close pool instruction. */
|
|
1523
|
+
closePool(authority) {
|
|
1524
|
+
return buildClosePool(
|
|
1525
|
+
authority,
|
|
1526
|
+
this.poolAddress,
|
|
1527
|
+
this.addresses.midpriceOracle,
|
|
1528
|
+
this.addresses.curveMeta,
|
|
1529
|
+
this.addresses.curvePrefabs,
|
|
1530
|
+
this.addresses.curveUpdates,
|
|
1531
|
+
this.addresses.vaultX,
|
|
1532
|
+
this.addresses.vaultY,
|
|
1533
|
+
this.config.tokenProgramX,
|
|
1534
|
+
this.config.tokenProgramY,
|
|
1535
|
+
this.config.spreadConfigInitialized,
|
|
1536
|
+
this.programId
|
|
1537
|
+
);
|
|
1538
|
+
}
|
|
1539
|
+
};
|
|
1540
|
+
|
|
1541
|
+
// src/helpers/token.ts
|
|
1542
|
+
import {
|
|
1543
|
+
getAssociatedTokenAddressSync as getAssociatedTokenAddressSync5,
|
|
1544
|
+
createAssociatedTokenAccountInstruction,
|
|
1545
|
+
TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID2
|
|
1546
|
+
} from "@solana/spl-token";
|
|
1547
|
+
async function getOrCreateAta(connection, mint, owner, payer, tokenProgram = TOKEN_PROGRAM_ID2, allowOwnerOffCurve = false) {
|
|
1548
|
+
const address = getAssociatedTokenAddressSync5(
|
|
1549
|
+
mint,
|
|
1550
|
+
owner,
|
|
1551
|
+
allowOwnerOffCurve,
|
|
1552
|
+
tokenProgram
|
|
1553
|
+
);
|
|
1554
|
+
const account = await connection.getAccountInfo(address);
|
|
1555
|
+
if (account) {
|
|
1556
|
+
return { address, instruction: null };
|
|
1557
|
+
}
|
|
1558
|
+
const instruction = createAssociatedTokenAccountInstruction(
|
|
1559
|
+
payer,
|
|
1560
|
+
address,
|
|
1561
|
+
owner,
|
|
1562
|
+
mint,
|
|
1563
|
+
tokenProgram
|
|
1564
|
+
);
|
|
1565
|
+
return { address, instruction };
|
|
1566
|
+
}
|
|
1567
|
+
export {
|
|
1568
|
+
ABSOLUTE_MAX_CURVE_POINTS,
|
|
1569
|
+
ABSOLUTE_MAX_PREFAB_SLOTS,
|
|
1570
|
+
CONFIG_SEED,
|
|
1571
|
+
CONFIG_SIZE,
|
|
1572
|
+
CURVE_META_SEED,
|
|
1573
|
+
CURVE_META_SIZE,
|
|
1574
|
+
CURVE_POINT_LEN,
|
|
1575
|
+
CURVE_PREFABS_SEED,
|
|
1576
|
+
CURVE_SIDE_HEADER,
|
|
1577
|
+
CURVE_UPDATES_SEED,
|
|
1578
|
+
CURVE_UPDATES_SIZE,
|
|
1579
|
+
CURVE_UPDATE_OP_SIZE,
|
|
1580
|
+
CurveType,
|
|
1581
|
+
CurveUpdateOpKind,
|
|
1582
|
+
CurveXMode,
|
|
1583
|
+
DEFAULT_MAX_CURVE_POINTS,
|
|
1584
|
+
DEFAULT_MAX_PREFAB_SLOTS,
|
|
1585
|
+
Discriminator,
|
|
1586
|
+
FEE_CONFIG_SEED,
|
|
1587
|
+
FEE_CONFIG_SIZE,
|
|
1588
|
+
HADRON_PROGRAM_ID,
|
|
1589
|
+
Hadron,
|
|
1590
|
+
Interpolation,
|
|
1591
|
+
MAX_CURVE_UPDATE_OPS,
|
|
1592
|
+
MAX_SETCURVE_POINTS,
|
|
1593
|
+
MIDPRICE_ORACLE_SEED,
|
|
1594
|
+
MIDPRICE_ORACLE_SIZE,
|
|
1595
|
+
OracleMode,
|
|
1596
|
+
POINT_DATA_SIZE,
|
|
1597
|
+
PoolState,
|
|
1598
|
+
Q32_ONE,
|
|
1599
|
+
RiskMode,
|
|
1600
|
+
SPREAD_CONFIG_SEED,
|
|
1601
|
+
Side,
|
|
1602
|
+
buildAcceptAuthority,
|
|
1603
|
+
buildAllocateCurvePrefabs,
|
|
1604
|
+
buildApplyCurveUpdates,
|
|
1605
|
+
buildClosePool,
|
|
1606
|
+
buildDeposit,
|
|
1607
|
+
buildInitialize,
|
|
1608
|
+
buildInitializeFeeConfig,
|
|
1609
|
+
buildInitializeSpreadConfig,
|
|
1610
|
+
buildNominateAuthority,
|
|
1611
|
+
buildRotateFeeAdmin,
|
|
1612
|
+
buildSetCurve,
|
|
1613
|
+
buildSetCurveBoth,
|
|
1614
|
+
buildSetPoolState,
|
|
1615
|
+
buildSetQuotingAuthority,
|
|
1616
|
+
buildSetRiskCurve,
|
|
1617
|
+
buildSetRiskCurveAbsolute,
|
|
1618
|
+
buildSetRiskCurveAbsoluteBoth,
|
|
1619
|
+
buildSetRiskCurveBoth,
|
|
1620
|
+
buildSubmitCurveUpdates,
|
|
1621
|
+
buildSwapExactIn,
|
|
1622
|
+
buildSwitchPriceCurve,
|
|
1623
|
+
buildSwitchRiskCurve,
|
|
1624
|
+
buildUpdateBaseSpread,
|
|
1625
|
+
buildUpdateDeltaStaleness,
|
|
1626
|
+
buildUpdateFeeConfig,
|
|
1627
|
+
buildUpdateMidprice,
|
|
1628
|
+
buildUpdateMidpriceAndBaseSpread,
|
|
1629
|
+
buildUpdateSpreadConfig,
|
|
1630
|
+
buildWithdraw,
|
|
1631
|
+
curvePrefabsSize,
|
|
1632
|
+
decodeActiveCurves,
|
|
1633
|
+
decodeConfig,
|
|
1634
|
+
decodeCurveMeta,
|
|
1635
|
+
decodeCurveSide,
|
|
1636
|
+
decodeCurveUpdates,
|
|
1637
|
+
decodeFeeConfig,
|
|
1638
|
+
decodeMidpriceOracle,
|
|
1639
|
+
derivePoolAddresses,
|
|
1640
|
+
fromQ32,
|
|
1641
|
+
getConfigAddress,
|
|
1642
|
+
getCurveMetaAddress,
|
|
1643
|
+
getCurvePrefabsAddress,
|
|
1644
|
+
getCurveUpdatesAddress,
|
|
1645
|
+
getFeeConfigAddress,
|
|
1646
|
+
getMidpriceOracleAddress,
|
|
1647
|
+
getOrCreateAta,
|
|
1648
|
+
getSpreadConfigAddress,
|
|
1649
|
+
isSlotInitialized,
|
|
1650
|
+
pctToQ32,
|
|
1651
|
+
toQ32
|
|
1652
|
+
};
|
|
1653
|
+
//# sourceMappingURL=index.mjs.map
|