@hadron-fi/sdk 0.3.4 → 0.4.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/dist/index.d.mts +64 -4
- package/dist/index.d.ts +64 -4
- package/dist/index.js +192 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +288 -107
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
|
+
// src/helpers/sol.ts
|
|
2
|
+
import {
|
|
3
|
+
SystemProgram
|
|
4
|
+
} from "@solana/web3.js";
|
|
5
|
+
import {
|
|
6
|
+
NATIVE_MINT,
|
|
7
|
+
createSyncNativeInstruction,
|
|
8
|
+
createCloseAccountInstruction,
|
|
9
|
+
TOKEN_PROGRAM_ID
|
|
10
|
+
} from "@solana/spl-token";
|
|
11
|
+
import {
|
|
12
|
+
getAssociatedTokenAddressSync,
|
|
13
|
+
createAssociatedTokenAccountIdempotentInstruction
|
|
14
|
+
} from "@solana/spl-token";
|
|
15
|
+
function isNativeMint(mint) {
|
|
16
|
+
return mint.equals(NATIVE_MINT);
|
|
17
|
+
}
|
|
18
|
+
function wrapSolInstructions(user, lamports) {
|
|
19
|
+
const ata = getAssociatedTokenAddressSync(NATIVE_MINT, user, false, TOKEN_PROGRAM_ID);
|
|
20
|
+
return [
|
|
21
|
+
createAssociatedTokenAccountIdempotentInstruction(
|
|
22
|
+
user,
|
|
23
|
+
ata,
|
|
24
|
+
user,
|
|
25
|
+
NATIVE_MINT,
|
|
26
|
+
TOKEN_PROGRAM_ID
|
|
27
|
+
),
|
|
28
|
+
SystemProgram.transfer({
|
|
29
|
+
fromPubkey: user,
|
|
30
|
+
toPubkey: ata,
|
|
31
|
+
lamports
|
|
32
|
+
}),
|
|
33
|
+
createSyncNativeInstruction(ata, TOKEN_PROGRAM_ID)
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
function createWsolAtaInstruction(user) {
|
|
37
|
+
const ata = getAssociatedTokenAddressSync(NATIVE_MINT, user, false, TOKEN_PROGRAM_ID);
|
|
38
|
+
return createAssociatedTokenAccountIdempotentInstruction(
|
|
39
|
+
user,
|
|
40
|
+
ata,
|
|
41
|
+
user,
|
|
42
|
+
NATIVE_MINT,
|
|
43
|
+
TOKEN_PROGRAM_ID
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
function unwrapSolInstruction(user) {
|
|
47
|
+
const ata = getAssociatedTokenAddressSync(NATIVE_MINT, user, false, TOKEN_PROGRAM_ID);
|
|
48
|
+
return createCloseAccountInstruction(ata, user, user, [], TOKEN_PROGRAM_ID);
|
|
49
|
+
}
|
|
50
|
+
|
|
1
51
|
// src/constants/index.ts
|
|
2
|
-
import { PublicKey } from "@solana/web3.js";
|
|
3
|
-
var HADRON_PROGRAM_ID = new
|
|
52
|
+
import { PublicKey as PublicKey2 } from "@solana/web3.js";
|
|
53
|
+
var HADRON_PROGRAM_ID = new PublicKey2(
|
|
4
54
|
"Q72w4coozA552keKDdeeh2EyQw32qfMFsHPu6cbatom"
|
|
5
55
|
);
|
|
6
56
|
var CONFIG_SEED = Buffer.from("hadron-config");
|
|
@@ -49,7 +99,9 @@ var Discriminator = {
|
|
|
49
99
|
SetPoolState: 21,
|
|
50
100
|
AllocateCurvePrefabs: 22,
|
|
51
101
|
SetQuotingAuthority: 23,
|
|
52
|
-
RotateFeeAdmin: 24
|
|
102
|
+
RotateFeeAdmin: 24,
|
|
103
|
+
InitializePoolFeeConfig: 25,
|
|
104
|
+
UpdatePoolFeeConfig: 26
|
|
53
105
|
};
|
|
54
106
|
var POINT_DATA_SIZE = 21;
|
|
55
107
|
var CURVE_UPDATE_OP_SIZE = 24;
|
|
@@ -58,21 +110,21 @@ function curvePrefabsSize(maxSlots, maxPoints) {
|
|
|
58
110
|
}
|
|
59
111
|
|
|
60
112
|
// src/helpers/derive.ts
|
|
61
|
-
import { PublicKey as
|
|
62
|
-
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
|
|
113
|
+
import { PublicKey as PublicKey3 } from "@solana/web3.js";
|
|
114
|
+
import { getAssociatedTokenAddressSync as getAssociatedTokenAddressSync2 } from "@solana/spl-token";
|
|
63
115
|
function seedToBuffer(seed) {
|
|
64
116
|
const buf = Buffer.alloc(8);
|
|
65
117
|
buf.writeBigUInt64LE(seed);
|
|
66
118
|
return buf;
|
|
67
119
|
}
|
|
68
120
|
function getConfigAddress(seed, mintX, mintY, programId = HADRON_PROGRAM_ID) {
|
|
69
|
-
return
|
|
121
|
+
return PublicKey3.findProgramAddressSync(
|
|
70
122
|
[CONFIG_SEED, seedToBuffer(seed), mintX.toBuffer(), mintY.toBuffer()],
|
|
71
123
|
programId
|
|
72
124
|
);
|
|
73
125
|
}
|
|
74
126
|
function getMidpriceOracleAddress(seed, mintX, mintY, programId = HADRON_PROGRAM_ID) {
|
|
75
|
-
return
|
|
127
|
+
return PublicKey3.findProgramAddressSync(
|
|
76
128
|
[
|
|
77
129
|
MIDPRICE_ORACLE_SEED,
|
|
78
130
|
seedToBuffer(seed),
|
|
@@ -83,13 +135,13 @@ function getMidpriceOracleAddress(seed, mintX, mintY, programId = HADRON_PROGRAM
|
|
|
83
135
|
);
|
|
84
136
|
}
|
|
85
137
|
function getCurveMetaAddress(seed, mintX, mintY, programId = HADRON_PROGRAM_ID) {
|
|
86
|
-
return
|
|
138
|
+
return PublicKey3.findProgramAddressSync(
|
|
87
139
|
[CURVE_META_SEED, seedToBuffer(seed), mintX.toBuffer(), mintY.toBuffer()],
|
|
88
140
|
programId
|
|
89
141
|
);
|
|
90
142
|
}
|
|
91
143
|
function getCurvePrefabsAddress(seed, mintX, mintY, programId = HADRON_PROGRAM_ID) {
|
|
92
|
-
return
|
|
144
|
+
return PublicKey3.findProgramAddressSync(
|
|
93
145
|
[
|
|
94
146
|
CURVE_PREFABS_SEED,
|
|
95
147
|
seedToBuffer(seed),
|
|
@@ -100,7 +152,7 @@ function getCurvePrefabsAddress(seed, mintX, mintY, programId = HADRON_PROGRAM_I
|
|
|
100
152
|
);
|
|
101
153
|
}
|
|
102
154
|
function getCurveUpdatesAddress(seed, mintX, mintY, programId = HADRON_PROGRAM_ID) {
|
|
103
|
-
return
|
|
155
|
+
return PublicKey3.findProgramAddressSync(
|
|
104
156
|
[
|
|
105
157
|
CURVE_UPDATES_SEED,
|
|
106
158
|
seedToBuffer(seed),
|
|
@@ -111,10 +163,16 @@ function getCurveUpdatesAddress(seed, mintX, mintY, programId = HADRON_PROGRAM_I
|
|
|
111
163
|
);
|
|
112
164
|
}
|
|
113
165
|
function getFeeConfigAddress(programId = HADRON_PROGRAM_ID) {
|
|
114
|
-
return
|
|
166
|
+
return PublicKey3.findProgramAddressSync([FEE_CONFIG_SEED], programId);
|
|
167
|
+
}
|
|
168
|
+
function getPoolFeeConfigAddress(configPda, programId = HADRON_PROGRAM_ID) {
|
|
169
|
+
return PublicKey3.findProgramAddressSync(
|
|
170
|
+
[FEE_CONFIG_SEED, configPda.toBuffer()],
|
|
171
|
+
programId
|
|
172
|
+
);
|
|
115
173
|
}
|
|
116
174
|
function getSpreadConfigAddress(configPda, programId = HADRON_PROGRAM_ID) {
|
|
117
|
-
return
|
|
175
|
+
return PublicKey3.findProgramAddressSync(
|
|
118
176
|
[SPREAD_CONFIG_SEED, configPda.toBuffer()],
|
|
119
177
|
programId
|
|
120
178
|
);
|
|
@@ -130,13 +188,13 @@ function derivePoolAddresses(seed, mintX, mintY, tokenProgramX, tokenProgramY, p
|
|
|
130
188
|
const [curveMeta] = getCurveMetaAddress(seed, mintX, mintY, programId);
|
|
131
189
|
const [curvePrefabs] = getCurvePrefabsAddress(seed, mintX, mintY, programId);
|
|
132
190
|
const [curveUpdates] = getCurveUpdatesAddress(seed, mintX, mintY, programId);
|
|
133
|
-
const vaultX =
|
|
191
|
+
const vaultX = getAssociatedTokenAddressSync2(
|
|
134
192
|
mintX,
|
|
135
193
|
config,
|
|
136
194
|
true,
|
|
137
195
|
tokenProgramX
|
|
138
196
|
);
|
|
139
|
-
const vaultY =
|
|
197
|
+
const vaultY = getAssociatedTokenAddressSync2(
|
|
140
198
|
mintY,
|
|
141
199
|
config,
|
|
142
200
|
true,
|
|
@@ -174,7 +232,7 @@ function spreadQ32ToBps(q32) {
|
|
|
174
232
|
}
|
|
175
233
|
|
|
176
234
|
// src/accounts/index.ts
|
|
177
|
-
import { PublicKey as
|
|
235
|
+
import { PublicKey as PublicKey4 } from "@solana/web3.js";
|
|
178
236
|
|
|
179
237
|
// src/types/index.ts
|
|
180
238
|
var PoolState = /* @__PURE__ */ ((PoolState3) => {
|
|
@@ -235,15 +293,15 @@ function decodeConfig(data) {
|
|
|
235
293
|
offset += 1;
|
|
236
294
|
const seed = buf.readBigUInt64LE(offset);
|
|
237
295
|
offset += 8;
|
|
238
|
-
const authority = new
|
|
296
|
+
const authority = new PublicKey4(buf.subarray(offset, offset + 32));
|
|
239
297
|
offset += 32;
|
|
240
|
-
const mintX = new
|
|
298
|
+
const mintX = new PublicKey4(buf.subarray(offset, offset + 32));
|
|
241
299
|
offset += 32;
|
|
242
|
-
const mintY = new
|
|
300
|
+
const mintY = new PublicKey4(buf.subarray(offset, offset + 32));
|
|
243
301
|
offset += 32;
|
|
244
302
|
const configBump = buf.readUInt8(offset);
|
|
245
303
|
offset += 1;
|
|
246
|
-
const curveMeta = new
|
|
304
|
+
const curveMeta = new PublicKey4(buf.subarray(offset, offset + 32));
|
|
247
305
|
offset += 32;
|
|
248
306
|
const spreadConfigInitialized = buf.readUInt8(offset) !== 0;
|
|
249
307
|
offset += 1;
|
|
@@ -251,14 +309,16 @@ function decodeConfig(data) {
|
|
|
251
309
|
offset += 1;
|
|
252
310
|
const oracleMode = buf.readUInt8(offset);
|
|
253
311
|
offset += 1;
|
|
254
|
-
offset
|
|
255
|
-
|
|
312
|
+
const hasPoolFee = buf.readUInt8(offset) !== 0;
|
|
313
|
+
offset += 1;
|
|
314
|
+
offset += 2;
|
|
315
|
+
const pendingAuthority = new PublicKey4(buf.subarray(offset, offset + 32));
|
|
256
316
|
offset += 32;
|
|
257
317
|
const nominationExpiry = buf.readBigUInt64LE(offset);
|
|
258
318
|
offset += 8;
|
|
259
|
-
const tokenProgramX = new
|
|
319
|
+
const tokenProgramX = new PublicKey4(buf.subarray(offset, offset + 32));
|
|
260
320
|
offset += 32;
|
|
261
|
-
const tokenProgramY = new
|
|
321
|
+
const tokenProgramY = new PublicKey4(buf.subarray(offset, offset + 32));
|
|
262
322
|
return {
|
|
263
323
|
state,
|
|
264
324
|
seed,
|
|
@@ -270,6 +330,7 @@ function decodeConfig(data) {
|
|
|
270
330
|
spreadConfigInitialized,
|
|
271
331
|
deltaStaleness,
|
|
272
332
|
oracleMode,
|
|
333
|
+
hasPoolFee,
|
|
273
334
|
pendingAuthority,
|
|
274
335
|
nominationExpiry,
|
|
275
336
|
tokenProgramX,
|
|
@@ -278,7 +339,7 @@ function decodeConfig(data) {
|
|
|
278
339
|
}
|
|
279
340
|
function decodeMidpriceOracle(data) {
|
|
280
341
|
const buf = Buffer.from(data);
|
|
281
|
-
const authority = new
|
|
342
|
+
const authority = new PublicKey4(buf.subarray(0, 32));
|
|
282
343
|
const sequence = buf.readBigUInt64LE(32);
|
|
283
344
|
const midpriceQ32 = buf.readBigUInt64LE(40);
|
|
284
345
|
const spreadFactorQ32 = buf.readBigUInt64LE(48);
|
|
@@ -288,7 +349,7 @@ function decodeMidpriceOracle(data) {
|
|
|
288
349
|
function decodeCurveMeta(data) {
|
|
289
350
|
const buf = Buffer.from(data);
|
|
290
351
|
return {
|
|
291
|
-
authority: new
|
|
352
|
+
authority: new PublicKey4(buf.subarray(0, 32)),
|
|
292
353
|
activePriceBidSlot: buf.readUInt8(32),
|
|
293
354
|
activePriceAskSlot: buf.readUInt8(33),
|
|
294
355
|
activeRiskBidSlot: buf.readUInt8(34),
|
|
@@ -311,8 +372,8 @@ function decodeFeeConfig(data) {
|
|
|
311
372
|
feePpm: buf.readUInt32LE(1),
|
|
312
373
|
bump: buf.readUInt8(5),
|
|
313
374
|
// skip 2 bytes padding
|
|
314
|
-
feeAdmin: new
|
|
315
|
-
feeRecipient: new
|
|
375
|
+
feeAdmin: new PublicKey4(buf.subarray(8, 40)),
|
|
376
|
+
feeRecipient: new PublicKey4(buf.subarray(40, 72))
|
|
316
377
|
};
|
|
317
378
|
}
|
|
318
379
|
var SPREAD_TRIGGER_LEN = 40;
|
|
@@ -321,13 +382,13 @@ function decodeSpreadConfig(data) {
|
|
|
321
382
|
const initialized = buf.readUInt8(0) !== 0;
|
|
322
383
|
const bump = buf.readUInt8(1);
|
|
323
384
|
const numTriggers = buf.readUInt8(2);
|
|
324
|
-
const admin = new
|
|
325
|
-
const config = new
|
|
385
|
+
const admin = new PublicKey4(buf.subarray(8, 40));
|
|
386
|
+
const config = new PublicKey4(buf.subarray(40, 72));
|
|
326
387
|
const triggers = [];
|
|
327
388
|
const triggersStart = 72;
|
|
328
389
|
for (let i = 0; i < numTriggers; i++) {
|
|
329
390
|
const off = triggersStart + i * SPREAD_TRIGGER_LEN;
|
|
330
|
-
const account = new
|
|
391
|
+
const account = new PublicKey4(buf.subarray(off, off + 32));
|
|
331
392
|
const spreadBps = buf.readUInt16LE(off + 32);
|
|
332
393
|
triggers.push({ account, spreadBps });
|
|
333
394
|
}
|
|
@@ -336,9 +397,9 @@ function decodeSpreadConfig(data) {
|
|
|
336
397
|
function decodeCurveUpdates(data) {
|
|
337
398
|
const buf = Buffer.from(data);
|
|
338
399
|
let offset = 0;
|
|
339
|
-
const authority = new
|
|
400
|
+
const authority = new PublicKey4(buf.subarray(offset, offset + 32));
|
|
340
401
|
offset += 32;
|
|
341
|
-
const curveMeta = new
|
|
402
|
+
const curveMeta = new PublicKey4(buf.subarray(offset, offset + 32));
|
|
342
403
|
offset += 32;
|
|
343
404
|
const numOps = buf.readUInt8(offset);
|
|
344
405
|
offset += 1;
|
|
@@ -416,16 +477,16 @@ function decodeActiveCurves(prefabsData, meta) {
|
|
|
416
477
|
|
|
417
478
|
// src/instructions/initialize.ts
|
|
418
479
|
import {
|
|
419
|
-
PublicKey as
|
|
420
|
-
SystemProgram,
|
|
421
|
-
TransactionInstruction
|
|
480
|
+
PublicKey as PublicKey5,
|
|
481
|
+
SystemProgram as SystemProgram2,
|
|
482
|
+
TransactionInstruction as TransactionInstruction2
|
|
422
483
|
} from "@solana/web3.js";
|
|
423
|
-
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
|
484
|
+
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID2 } from "@solana/spl-token";
|
|
424
485
|
function buildInitialize(payer, params, programId = HADRON_PROGRAM_ID) {
|
|
425
486
|
const seed = params.seed;
|
|
426
487
|
if (seed === void 0) throw new Error("seed is required \u2014 use Hadron.initialize() to auto-generate one");
|
|
427
|
-
const tokenProgramX = params.tokenProgramX ??
|
|
428
|
-
const tokenProgramY = params.tokenProgramY ??
|
|
488
|
+
const tokenProgramX = params.tokenProgramX ?? TOKEN_PROGRAM_ID2;
|
|
489
|
+
const tokenProgramY = params.tokenProgramY ?? TOKEN_PROGRAM_ID2;
|
|
429
490
|
const maxPrefabSlots = params.maxPrefabSlots ?? DEFAULT_MAX_PREFAB_SLOTS;
|
|
430
491
|
const maxCurvePoints = params.maxCurvePoints ?? DEFAULT_MAX_CURVE_POINTS;
|
|
431
492
|
const oracleMode = params.oracleMode ?? 0;
|
|
@@ -463,7 +524,7 @@ function buildInitialize(payer, params, programId = HADRON_PROGRAM_ID) {
|
|
|
463
524
|
offset += 1;
|
|
464
525
|
data.writeUInt8(maxCurvePoints, offset);
|
|
465
526
|
}
|
|
466
|
-
return new
|
|
527
|
+
return new TransactionInstruction2({
|
|
467
528
|
programId,
|
|
468
529
|
keys: [
|
|
469
530
|
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
@@ -479,7 +540,7 @@ function buildInitialize(payer, params, programId = HADRON_PROGRAM_ID) {
|
|
|
479
540
|
isSigner: false,
|
|
480
541
|
isWritable: false
|
|
481
542
|
},
|
|
482
|
-
{ pubkey:
|
|
543
|
+
{ pubkey: SystemProgram2.programId, isSigner: false, isWritable: false },
|
|
483
544
|
{ pubkey: addrs.midpriceOracle, isSigner: false, isWritable: true },
|
|
484
545
|
{ pubkey: addrs.curveMeta, isSigner: false, isWritable: true },
|
|
485
546
|
{ pubkey: addrs.curvePrefabs, isSigner: false, isWritable: true },
|
|
@@ -491,7 +552,7 @@ function buildInitialize(payer, params, programId = HADRON_PROGRAM_ID) {
|
|
|
491
552
|
function buildAllocateCurvePrefabs(payer, params, programId = HADRON_PROGRAM_ID) {
|
|
492
553
|
const maxPrefabSlots = params.maxPrefabSlots ?? DEFAULT_MAX_PREFAB_SLOTS;
|
|
493
554
|
const maxCurvePoints = params.maxCurvePoints ?? DEFAULT_MAX_CURVE_POINTS;
|
|
494
|
-
const data = Buffer.alloc(1 + 8 + 32 + 32 + 1 + 1);
|
|
555
|
+
const data = Buffer.alloc(1 + 8 + 32 + 32 + 1 + 1 + 32);
|
|
495
556
|
let offset = 0;
|
|
496
557
|
data.writeUInt8(Discriminator.AllocateCurvePrefabs, offset);
|
|
497
558
|
offset += 1;
|
|
@@ -504,7 +565,9 @@ function buildAllocateCurvePrefabs(payer, params, programId = HADRON_PROGRAM_ID)
|
|
|
504
565
|
data.writeUInt8(maxPrefabSlots, offset);
|
|
505
566
|
offset += 1;
|
|
506
567
|
data.writeUInt8(maxCurvePoints, offset);
|
|
507
|
-
|
|
568
|
+
offset += 1;
|
|
569
|
+
params.authority.toBuffer().copy(data, offset);
|
|
570
|
+
const [curvePrefabsPda] = PublicKey5.findProgramAddressSync(
|
|
508
571
|
[
|
|
509
572
|
Buffer.from("hadron-curve-prefabs"),
|
|
510
573
|
(() => {
|
|
@@ -517,20 +580,20 @@ function buildAllocateCurvePrefabs(payer, params, programId = HADRON_PROGRAM_ID)
|
|
|
517
580
|
],
|
|
518
581
|
programId
|
|
519
582
|
);
|
|
520
|
-
return new
|
|
583
|
+
return new TransactionInstruction2({
|
|
521
584
|
programId,
|
|
522
585
|
keys: [
|
|
523
586
|
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
524
587
|
{ pubkey: curvePrefabsPda, isSigner: false, isWritable: true },
|
|
525
|
-
{ pubkey:
|
|
588
|
+
{ pubkey: SystemProgram2.programId, isSigner: false, isWritable: false }
|
|
526
589
|
],
|
|
527
590
|
data
|
|
528
591
|
});
|
|
529
592
|
}
|
|
530
593
|
|
|
531
594
|
// src/instructions/deposit.ts
|
|
532
|
-
import { TransactionInstruction as
|
|
533
|
-
import { getAssociatedTokenAddressSync as
|
|
595
|
+
import { TransactionInstruction as TransactionInstruction3 } from "@solana/web3.js";
|
|
596
|
+
import { getAssociatedTokenAddressSync as getAssociatedTokenAddressSync3 } from "@solana/spl-token";
|
|
534
597
|
function buildDeposit(user, configPda, mintX, mintY, tokenProgramX, tokenProgramY, params, programId = HADRON_PROGRAM_ID) {
|
|
535
598
|
const data = Buffer.alloc(1 + 8 + 8 + 8);
|
|
536
599
|
let offset = 0;
|
|
@@ -542,11 +605,11 @@ function buildDeposit(user, configPda, mintX, mintY, tokenProgramX, tokenProgram
|
|
|
542
605
|
offset += 8;
|
|
543
606
|
const exp = params.expiration ?? Math.floor(Date.now() / 1e3) + 3600;
|
|
544
607
|
data.writeBigInt64LE(BigInt(exp), offset);
|
|
545
|
-
const userX =
|
|
546
|
-
const userY =
|
|
547
|
-
const vaultX =
|
|
548
|
-
const vaultY =
|
|
549
|
-
return new
|
|
608
|
+
const userX = getAssociatedTokenAddressSync3(mintX, user, false, tokenProgramX);
|
|
609
|
+
const userY = getAssociatedTokenAddressSync3(mintY, user, false, tokenProgramY);
|
|
610
|
+
const vaultX = getAssociatedTokenAddressSync3(mintX, configPda, true, tokenProgramX);
|
|
611
|
+
const vaultY = getAssociatedTokenAddressSync3(mintY, configPda, true, tokenProgramY);
|
|
612
|
+
return new TransactionInstruction3({
|
|
550
613
|
programId,
|
|
551
614
|
keys: [
|
|
552
615
|
{ pubkey: user, isSigner: true, isWritable: false },
|
|
@@ -563,8 +626,8 @@ function buildDeposit(user, configPda, mintX, mintY, tokenProgramX, tokenProgram
|
|
|
563
626
|
}
|
|
564
627
|
|
|
565
628
|
// src/instructions/withdraw.ts
|
|
566
|
-
import { TransactionInstruction as
|
|
567
|
-
import { getAssociatedTokenAddressSync as
|
|
629
|
+
import { TransactionInstruction as TransactionInstruction4 } from "@solana/web3.js";
|
|
630
|
+
import { getAssociatedTokenAddressSync as getAssociatedTokenAddressSync4 } from "@solana/spl-token";
|
|
568
631
|
function buildWithdraw(user, configPda, mintX, mintY, tokenProgramX, tokenProgramY, params, programId = HADRON_PROGRAM_ID) {
|
|
569
632
|
const data = Buffer.alloc(1 + 8 + 8 + 8);
|
|
570
633
|
let offset = 0;
|
|
@@ -576,11 +639,11 @@ function buildWithdraw(user, configPda, mintX, mintY, tokenProgramX, tokenProgra
|
|
|
576
639
|
offset += 8;
|
|
577
640
|
const exp = params.expiration ?? Math.floor(Date.now() / 1e3) + 3600;
|
|
578
641
|
data.writeBigInt64LE(BigInt(exp), offset);
|
|
579
|
-
const userX =
|
|
580
|
-
const userY =
|
|
581
|
-
const vaultX =
|
|
582
|
-
const vaultY =
|
|
583
|
-
return new
|
|
642
|
+
const userX = getAssociatedTokenAddressSync4(mintX, user, false, tokenProgramX);
|
|
643
|
+
const userY = getAssociatedTokenAddressSync4(mintY, user, false, tokenProgramY);
|
|
644
|
+
const vaultX = getAssociatedTokenAddressSync4(mintX, configPda, true, tokenProgramX);
|
|
645
|
+
const vaultY = getAssociatedTokenAddressSync4(mintY, configPda, true, tokenProgramY);
|
|
646
|
+
return new TransactionInstruction4({
|
|
584
647
|
programId,
|
|
585
648
|
keys: [
|
|
586
649
|
{ pubkey: user, isSigner: true, isWritable: false },
|
|
@@ -600,10 +663,10 @@ function buildWithdraw(user, configPda, mintX, mintY, tokenProgramX, tokenProgra
|
|
|
600
663
|
import {
|
|
601
664
|
SYSVAR_CLOCK_PUBKEY,
|
|
602
665
|
SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
603
|
-
TransactionInstruction as
|
|
666
|
+
TransactionInstruction as TransactionInstruction5
|
|
604
667
|
} from "@solana/web3.js";
|
|
605
|
-
import { getAssociatedTokenAddressSync as
|
|
606
|
-
function buildSwapExactIn(user, poolAddresses, mintX, mintY, tokenProgramX, tokenProgramY, params, programId = HADRON_PROGRAM_ID, spreadConfigInitialized = false) {
|
|
668
|
+
import { getAssociatedTokenAddressSync as getAssociatedTokenAddressSync5 } from "@solana/spl-token";
|
|
669
|
+
function buildSwapExactIn(user, poolAddresses, mintX, mintY, tokenProgramX, tokenProgramY, params, programId = HADRON_PROGRAM_ID, spreadConfigInitialized = false, feeConfigOverride) {
|
|
607
670
|
const data = Buffer.alloc(1 + 1 + 8 + 8 + 8);
|
|
608
671
|
let offset = 0;
|
|
609
672
|
data.writeUInt8(Discriminator.SwapExactIn, offset);
|
|
@@ -616,13 +679,13 @@ function buildSwapExactIn(user, poolAddresses, mintX, mintY, tokenProgramX, toke
|
|
|
616
679
|
offset += 8;
|
|
617
680
|
const exp = params.expiration ?? Math.floor(Date.now() / 1e3) + 3600;
|
|
618
681
|
data.writeBigInt64LE(BigInt(exp), offset);
|
|
619
|
-
const userX =
|
|
620
|
-
const userY =
|
|
682
|
+
const userX = getAssociatedTokenAddressSync5(mintX, user, false, tokenProgramX);
|
|
683
|
+
const userY = getAssociatedTokenAddressSync5(mintY, user, false, tokenProgramY);
|
|
621
684
|
const [userSource, vaultSource, vaultDest, userDest] = params.isX ? [userX, poolAddresses.vaultX, poolAddresses.vaultY, userY] : [userY, poolAddresses.vaultY, poolAddresses.vaultX, userX];
|
|
622
|
-
const
|
|
685
|
+
const feeConfigPda = feeConfigOverride ?? getFeeConfigAddress(programId)[0];
|
|
623
686
|
const inputMint = params.isX ? mintX : mintY;
|
|
624
687
|
const inputMintProgram = params.isX ? tokenProgramX : tokenProgramY;
|
|
625
|
-
const feeRecipientAta =
|
|
688
|
+
const feeRecipientAta = getAssociatedTokenAddressSync5(
|
|
626
689
|
inputMint,
|
|
627
690
|
params.feeRecipient,
|
|
628
691
|
false,
|
|
@@ -669,7 +732,7 @@ function buildSwapExactIn(user, poolAddresses, mintX, mintY, tokenProgramX, toke
|
|
|
669
732
|
{ pubkey: SYSVAR_INSTRUCTIONS_PUBKEY, isSigner: false, isWritable: false }
|
|
670
733
|
);
|
|
671
734
|
}
|
|
672
|
-
return new
|
|
735
|
+
return new TransactionInstruction5({
|
|
673
736
|
programId,
|
|
674
737
|
keys,
|
|
675
738
|
data
|
|
@@ -677,7 +740,7 @@ function buildSwapExactIn(user, poolAddresses, mintX, mintY, tokenProgramX, toke
|
|
|
677
740
|
}
|
|
678
741
|
|
|
679
742
|
// src/instructions/setCurve.ts
|
|
680
|
-
import { TransactionInstruction as
|
|
743
|
+
import { TransactionInstruction as TransactionInstruction6 } from "@solana/web3.js";
|
|
681
744
|
function interpolationToByte(interp) {
|
|
682
745
|
return interp;
|
|
683
746
|
}
|
|
@@ -713,7 +776,7 @@ function buildSetCurve(authority, curveMetaPda, curvePrefabsPda, params, program
|
|
|
713
776
|
Buffer.from(params_).copy(data, offset, 0, 4);
|
|
714
777
|
offset += 4;
|
|
715
778
|
}
|
|
716
|
-
return new
|
|
779
|
+
return new TransactionInstruction6({
|
|
717
780
|
programId,
|
|
718
781
|
keys: [
|
|
719
782
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -760,7 +823,7 @@ function buildSetRiskCurve(authority, curveMetaPda, curvePrefabsPda, params, pro
|
|
|
760
823
|
Buffer.from(params_).copy(data, offset, 0, 4);
|
|
761
824
|
offset += 4;
|
|
762
825
|
}
|
|
763
|
-
return new
|
|
826
|
+
return new TransactionInstruction6({
|
|
764
827
|
programId,
|
|
765
828
|
keys: [
|
|
766
829
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -806,7 +869,7 @@ function buildSetRiskCurveAbsolute(authority, curveMetaPda, curvePrefabsPda, par
|
|
|
806
869
|
Buffer.from(params_).copy(data, offset, 0, 4);
|
|
807
870
|
offset += 4;
|
|
808
871
|
}
|
|
809
|
-
return new
|
|
872
|
+
return new TransactionInstruction6({
|
|
810
873
|
programId,
|
|
811
874
|
keys: [
|
|
812
875
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -835,14 +898,14 @@ function buildSetRiskCurveAbsoluteBoth(authority, curveMetaPda, curvePrefabsPda,
|
|
|
835
898
|
// src/instructions/oracle.ts
|
|
836
899
|
import {
|
|
837
900
|
SYSVAR_CLOCK_PUBKEY as SYSVAR_CLOCK_PUBKEY2,
|
|
838
|
-
TransactionInstruction as
|
|
901
|
+
TransactionInstruction as TransactionInstruction7
|
|
839
902
|
} from "@solana/web3.js";
|
|
840
903
|
function buildUpdateMidprice(authority, midpriceOraclePda, params, programId = HADRON_PROGRAM_ID) {
|
|
841
904
|
const data = Buffer.alloc(1 + 8 + 8);
|
|
842
905
|
data.writeUInt8(Discriminator.UpdateMidprice, 0);
|
|
843
906
|
data.writeBigUInt64LE(params.sequence ?? 0n, 1);
|
|
844
907
|
data.writeBigUInt64LE(params.midpriceQ32, 9);
|
|
845
|
-
return new
|
|
908
|
+
return new TransactionInstruction7({
|
|
846
909
|
programId,
|
|
847
910
|
keys: [
|
|
848
911
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -857,7 +920,7 @@ function buildUpdateBaseSpread(authority, midpriceOraclePda, params, programId =
|
|
|
857
920
|
data.writeUInt8(Discriminator.UpdateBaseSpread, 0);
|
|
858
921
|
data.writeBigUInt64LE(params.sequence ?? 0n, 1);
|
|
859
922
|
data.writeBigUInt64LE(params.spreadFactorQ32, 9);
|
|
860
|
-
return new
|
|
923
|
+
return new TransactionInstruction7({
|
|
861
924
|
programId,
|
|
862
925
|
keys: [
|
|
863
926
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -873,7 +936,7 @@ function buildUpdateMidpriceAndBaseSpread(authority, midpriceOraclePda, params,
|
|
|
873
936
|
data.writeBigUInt64LE(params.sequence ?? 0n, 1);
|
|
874
937
|
data.writeBigUInt64LE(params.midpriceQ32, 9);
|
|
875
938
|
data.writeBigUInt64LE(params.spreadFactorQ32, 17);
|
|
876
|
-
return new
|
|
939
|
+
return new TransactionInstruction7({
|
|
877
940
|
programId,
|
|
878
941
|
keys: [
|
|
879
942
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -885,13 +948,13 @@ function buildUpdateMidpriceAndBaseSpread(authority, midpriceOraclePda, params,
|
|
|
885
948
|
}
|
|
886
949
|
|
|
887
950
|
// src/instructions/switchCurve.ts
|
|
888
|
-
import { TransactionInstruction as
|
|
951
|
+
import { TransactionInstruction as TransactionInstruction8 } from "@solana/web3.js";
|
|
889
952
|
function buildSwitchPriceCurve(authority, curveMetaPda, params, programId = HADRON_PROGRAM_ID) {
|
|
890
953
|
const data = Buffer.alloc(1 + 1 + 1);
|
|
891
954
|
data.writeUInt8(Discriminator.SwitchPriceCurve, 0);
|
|
892
955
|
data.writeUInt8(params.side, 1);
|
|
893
956
|
data.writeUInt8(params.slot, 2);
|
|
894
|
-
return new
|
|
957
|
+
return new TransactionInstruction8({
|
|
895
958
|
programId,
|
|
896
959
|
keys: [
|
|
897
960
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -905,7 +968,7 @@ function buildSwitchRiskCurve(authority, curveMetaPda, params, programId = HADRO
|
|
|
905
968
|
data.writeUInt8(Discriminator.SwitchRiskCurve, 0);
|
|
906
969
|
data.writeUInt8(params.side, 1);
|
|
907
970
|
data.writeUInt8(params.slot, 2);
|
|
908
|
-
return new
|
|
971
|
+
return new TransactionInstruction8({
|
|
909
972
|
programId,
|
|
910
973
|
keys: [
|
|
911
974
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -916,7 +979,7 @@ function buildSwitchRiskCurve(authority, curveMetaPda, params, programId = HADRO
|
|
|
916
979
|
}
|
|
917
980
|
|
|
918
981
|
// src/instructions/curveUpdates.ts
|
|
919
|
-
import { TransactionInstruction as
|
|
982
|
+
import { TransactionInstruction as TransactionInstruction9 } from "@solana/web3.js";
|
|
920
983
|
function buildSubmitCurveUpdates(authority, curveUpdatesPda, ops, programId = HADRON_PROGRAM_ID) {
|
|
921
984
|
const data = Buffer.alloc(1 + 1 + ops.length * CURVE_UPDATE_OP_SIZE);
|
|
922
985
|
let offset = 0;
|
|
@@ -941,7 +1004,7 @@ function buildSubmitCurveUpdates(authority, curveUpdatesPda, ops, programId = HA
|
|
|
941
1004
|
Buffer.from(params).copy(data, offset, 0, 4);
|
|
942
1005
|
offset += 4;
|
|
943
1006
|
}
|
|
944
|
-
return new
|
|
1007
|
+
return new TransactionInstruction9({
|
|
945
1008
|
programId,
|
|
946
1009
|
keys: [
|
|
947
1010
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -953,7 +1016,7 @@ function buildSubmitCurveUpdates(authority, curveUpdatesPda, ops, programId = HA
|
|
|
953
1016
|
function buildApplyCurveUpdates(authority, curveMetaPda, curvePrefabsPda, curveUpdatesPda, programId = HADRON_PROGRAM_ID) {
|
|
954
1017
|
const data = Buffer.alloc(1);
|
|
955
1018
|
data.writeUInt8(Discriminator.ApplyCurveUpdates, 0);
|
|
956
|
-
return new
|
|
1019
|
+
return new TransactionInstruction9({
|
|
957
1020
|
programId,
|
|
958
1021
|
keys: [
|
|
959
1022
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -968,7 +1031,7 @@ function buildApplyCurveUpdates(authority, curveMetaPda, curvePrefabsPda, curveU
|
|
|
968
1031
|
// src/instructions/authority.ts
|
|
969
1032
|
import {
|
|
970
1033
|
SYSVAR_CLOCK_PUBKEY as SYSVAR_CLOCK_PUBKEY3,
|
|
971
|
-
TransactionInstruction as
|
|
1034
|
+
TransactionInstruction as TransactionInstruction10
|
|
972
1035
|
} from "@solana/web3.js";
|
|
973
1036
|
function buildNominateAuthority(authority, configPda, params, programId = HADRON_PROGRAM_ID) {
|
|
974
1037
|
const data = Buffer.alloc(1 + 32 + 8);
|
|
@@ -978,7 +1041,7 @@ function buildNominateAuthority(authority, configPda, params, programId = HADRON
|
|
|
978
1041
|
params.newAuthority.toBuffer().copy(data, offset);
|
|
979
1042
|
offset += 32;
|
|
980
1043
|
data.writeBigUInt64LE(params.expirySlot, offset);
|
|
981
|
-
return new
|
|
1044
|
+
return new TransactionInstruction10({
|
|
982
1045
|
programId,
|
|
983
1046
|
keys: [
|
|
984
1047
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -991,7 +1054,7 @@ function buildNominateAuthority(authority, configPda, params, programId = HADRON
|
|
|
991
1054
|
function buildAcceptAuthority(newAuthority, configPda, programId = HADRON_PROGRAM_ID) {
|
|
992
1055
|
const data = Buffer.alloc(1);
|
|
993
1056
|
data.writeUInt8(Discriminator.AcceptAuthority, 0);
|
|
994
|
-
return new
|
|
1057
|
+
return new TransactionInstruction10({
|
|
995
1058
|
programId,
|
|
996
1059
|
keys: [
|
|
997
1060
|
{ pubkey: newAuthority, isSigner: true, isWritable: false },
|
|
@@ -1019,7 +1082,7 @@ function buildSetQuotingAuthority(authority, configPda, oraclePda, curveMetaPda,
|
|
|
1019
1082
|
isWritable: true
|
|
1020
1083
|
});
|
|
1021
1084
|
}
|
|
1022
|
-
return new
|
|
1085
|
+
return new TransactionInstruction10({
|
|
1023
1086
|
programId,
|
|
1024
1087
|
keys,
|
|
1025
1088
|
data
|
|
@@ -1028,8 +1091,8 @@ function buildSetQuotingAuthority(authority, configPda, oraclePda, curveMetaPda,
|
|
|
1028
1091
|
|
|
1029
1092
|
// src/instructions/feeConfig.ts
|
|
1030
1093
|
import {
|
|
1031
|
-
SystemProgram as
|
|
1032
|
-
TransactionInstruction as
|
|
1094
|
+
SystemProgram as SystemProgram3,
|
|
1095
|
+
TransactionInstruction as TransactionInstruction11
|
|
1033
1096
|
} from "@solana/web3.js";
|
|
1034
1097
|
function buildInitializeFeeConfig(payer, authority, params, programId = HADRON_PROGRAM_ID) {
|
|
1035
1098
|
const [feeConfigPda] = getFeeConfigAddress(programId);
|
|
@@ -1042,13 +1105,13 @@ function buildInitializeFeeConfig(payer, authority, params, programId = HADRON_P
|
|
|
1042
1105
|
params.feeAdmin.toBuffer().copy(data, offset);
|
|
1043
1106
|
offset += 32;
|
|
1044
1107
|
params.feeRecipient.toBuffer().copy(data, offset);
|
|
1045
|
-
return new
|
|
1108
|
+
return new TransactionInstruction11({
|
|
1046
1109
|
programId,
|
|
1047
1110
|
keys: [
|
|
1048
1111
|
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
1049
1112
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
1050
1113
|
{ pubkey: feeConfigPda, isSigner: false, isWritable: true },
|
|
1051
|
-
{ pubkey:
|
|
1114
|
+
{ pubkey: SystemProgram3.programId, isSigner: false, isWritable: false }
|
|
1052
1115
|
],
|
|
1053
1116
|
data
|
|
1054
1117
|
});
|
|
@@ -1064,7 +1127,7 @@ function buildUpdateFeeConfig(feeAdmin, params, programId = HADRON_PROGRAM_ID) {
|
|
|
1064
1127
|
if (params.feeRecipient) {
|
|
1065
1128
|
params.feeRecipient.toBuffer().copy(data, offset);
|
|
1066
1129
|
}
|
|
1067
|
-
return new
|
|
1130
|
+
return new TransactionInstruction11({
|
|
1068
1131
|
programId,
|
|
1069
1132
|
keys: [
|
|
1070
1133
|
{ pubkey: feeAdmin, isSigner: true, isWritable: false },
|
|
@@ -1078,7 +1141,7 @@ function buildRotateFeeAdmin(feeAdmin, params, programId = HADRON_PROGRAM_ID) {
|
|
|
1078
1141
|
const data = Buffer.alloc(1 + 32);
|
|
1079
1142
|
data.writeUInt8(Discriminator.RotateFeeAdmin, 0);
|
|
1080
1143
|
params.newFeeAdmin.toBuffer().copy(data, 1);
|
|
1081
|
-
return new
|
|
1144
|
+
return new TransactionInstruction11({
|
|
1082
1145
|
programId,
|
|
1083
1146
|
keys: [
|
|
1084
1147
|
{ pubkey: feeAdmin, isSigner: true, isWritable: false },
|
|
@@ -1087,25 +1150,71 @@ function buildRotateFeeAdmin(feeAdmin, params, programId = HADRON_PROGRAM_ID) {
|
|
|
1087
1150
|
data
|
|
1088
1151
|
});
|
|
1089
1152
|
}
|
|
1153
|
+
function buildInitializePoolFeeConfig(payer, feeAdmin, configPda, params, programId = HADRON_PROGRAM_ID) {
|
|
1154
|
+
const [poolFeeConfigPda] = getPoolFeeConfigAddress(configPda, programId);
|
|
1155
|
+
const [globalFeeConfigPda] = getFeeConfigAddress(programId);
|
|
1156
|
+
const data = Buffer.alloc(1 + 4 + 32 + 32);
|
|
1157
|
+
let offset = 0;
|
|
1158
|
+
data.writeUInt8(Discriminator.InitializePoolFeeConfig, offset);
|
|
1159
|
+
offset += 1;
|
|
1160
|
+
data.writeUInt32LE(params.feePpm, offset);
|
|
1161
|
+
offset += 4;
|
|
1162
|
+
params.feeAdmin.toBuffer().copy(data, offset);
|
|
1163
|
+
offset += 32;
|
|
1164
|
+
params.feeRecipient.toBuffer().copy(data, offset);
|
|
1165
|
+
return new TransactionInstruction11({
|
|
1166
|
+
programId,
|
|
1167
|
+
keys: [
|
|
1168
|
+
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
1169
|
+
{ pubkey: feeAdmin, isSigner: true, isWritable: false },
|
|
1170
|
+
{ pubkey: configPda, isSigner: false, isWritable: true },
|
|
1171
|
+
{ pubkey: poolFeeConfigPda, isSigner: false, isWritable: true },
|
|
1172
|
+
{ pubkey: globalFeeConfigPda, isSigner: false, isWritable: false },
|
|
1173
|
+
{ pubkey: SystemProgram3.programId, isSigner: false, isWritable: false }
|
|
1174
|
+
],
|
|
1175
|
+
data
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1178
|
+
function buildUpdatePoolFeeConfig(feeAdmin, configPda, params, programId = HADRON_PROGRAM_ID) {
|
|
1179
|
+
const [poolFeeConfigPda] = getPoolFeeConfigAddress(configPda, programId);
|
|
1180
|
+
const data = Buffer.alloc(1 + 4 + 32);
|
|
1181
|
+
let offset = 0;
|
|
1182
|
+
data.writeUInt8(Discriminator.UpdatePoolFeeConfig, offset);
|
|
1183
|
+
offset += 1;
|
|
1184
|
+
data.writeUInt32LE(params.feePpm !== null ? params.feePpm : 4294967295, offset);
|
|
1185
|
+
offset += 4;
|
|
1186
|
+
if (params.feeRecipient) {
|
|
1187
|
+
params.feeRecipient.toBuffer().copy(data, offset);
|
|
1188
|
+
}
|
|
1189
|
+
return new TransactionInstruction11({
|
|
1190
|
+
programId,
|
|
1191
|
+
keys: [
|
|
1192
|
+
{ pubkey: feeAdmin, isSigner: true, isWritable: false },
|
|
1193
|
+
{ pubkey: configPda, isSigner: false, isWritable: false },
|
|
1194
|
+
{ pubkey: poolFeeConfigPda, isSigner: false, isWritable: true }
|
|
1195
|
+
],
|
|
1196
|
+
data
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1090
1199
|
|
|
1091
1200
|
// src/instructions/spreadConfig.ts
|
|
1092
1201
|
import {
|
|
1093
|
-
SystemProgram as
|
|
1094
|
-
TransactionInstruction as
|
|
1202
|
+
SystemProgram as SystemProgram4,
|
|
1203
|
+
TransactionInstruction as TransactionInstruction12
|
|
1095
1204
|
} from "@solana/web3.js";
|
|
1096
1205
|
function buildInitializeSpreadConfig(payer, authority, configPda, params, programId = HADRON_PROGRAM_ID) {
|
|
1097
1206
|
const [spreadConfigPda] = getSpreadConfigAddress(configPda, programId);
|
|
1098
1207
|
const data = Buffer.alloc(1 + 32);
|
|
1099
1208
|
data.writeUInt8(Discriminator.InitializeSpreadConfig, 0);
|
|
1100
1209
|
params.admin.toBuffer().copy(data, 1);
|
|
1101
|
-
return new
|
|
1210
|
+
return new TransactionInstruction12({
|
|
1102
1211
|
programId,
|
|
1103
1212
|
keys: [
|
|
1104
1213
|
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
1105
1214
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
1106
1215
|
{ pubkey: configPda, isSigner: false, isWritable: true },
|
|
1107
1216
|
{ pubkey: spreadConfigPda, isSigner: false, isWritable: true },
|
|
1108
|
-
{ pubkey:
|
|
1217
|
+
{ pubkey: SystemProgram4.programId, isSigner: false, isWritable: false }
|
|
1109
1218
|
],
|
|
1110
1219
|
data
|
|
1111
1220
|
});
|
|
@@ -1125,7 +1234,7 @@ function buildUpdateSpreadConfig(admin, configPda, params, programId = HADRON_PR
|
|
|
1125
1234
|
data.writeUInt16LE(t.spreadBps, offset);
|
|
1126
1235
|
offset += 2;
|
|
1127
1236
|
}
|
|
1128
|
-
return new
|
|
1237
|
+
return new TransactionInstruction12({
|
|
1129
1238
|
programId,
|
|
1130
1239
|
keys: [
|
|
1131
1240
|
{ pubkey: admin, isSigner: true, isWritable: false },
|
|
@@ -1138,13 +1247,13 @@ function buildUpdateSpreadConfig(admin, configPda, params, programId = HADRON_PR
|
|
|
1138
1247
|
|
|
1139
1248
|
// src/instructions/poolState.ts
|
|
1140
1249
|
import {
|
|
1141
|
-
TransactionInstruction as
|
|
1250
|
+
TransactionInstruction as TransactionInstruction13
|
|
1142
1251
|
} from "@solana/web3.js";
|
|
1143
1252
|
function buildSetPoolState(authority, configPda, params, programId = HADRON_PROGRAM_ID) {
|
|
1144
1253
|
const data = Buffer.alloc(1 + 1);
|
|
1145
1254
|
data.writeUInt8(Discriminator.SetPoolState, 0);
|
|
1146
1255
|
data.writeUInt8(params.newState, 1);
|
|
1147
|
-
return new
|
|
1256
|
+
return new TransactionInstruction13({
|
|
1148
1257
|
programId,
|
|
1149
1258
|
keys: [
|
|
1150
1259
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -1157,7 +1266,7 @@ function buildUpdateDeltaStaleness(authority, configPda, params, programId = HAD
|
|
|
1157
1266
|
const data = Buffer.alloc(1 + 1);
|
|
1158
1267
|
data.writeUInt8(Discriminator.UpdateDeltaStaleness, 0);
|
|
1159
1268
|
data.writeUInt8(params.deltaStaleness, 1);
|
|
1160
|
-
return new
|
|
1269
|
+
return new TransactionInstruction13({
|
|
1161
1270
|
programId,
|
|
1162
1271
|
keys: [
|
|
1163
1272
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -1166,7 +1275,7 @@ function buildUpdateDeltaStaleness(authority, configPda, params, programId = HAD
|
|
|
1166
1275
|
data
|
|
1167
1276
|
});
|
|
1168
1277
|
}
|
|
1169
|
-
function buildClosePool(authority, configPda, midpriceOraclePda, curveMetaPda, curvePrefabsPda, curveUpdatesPda, vaultX, vaultY, tokenProgramX, tokenProgramY, spreadConfigInitialized = false, programId = HADRON_PROGRAM_ID) {
|
|
1278
|
+
function buildClosePool(authority, configPda, midpriceOraclePda, curveMetaPda, curvePrefabsPda, curveUpdatesPda, vaultX, vaultY, tokenProgramX, tokenProgramY, spreadConfigInitialized = false, authorityAtaX, authorityAtaY, programId = HADRON_PROGRAM_ID) {
|
|
1170
1279
|
const data = Buffer.alloc(1);
|
|
1171
1280
|
data.writeUInt8(Discriminator.ClosePool, 0);
|
|
1172
1281
|
const keys = [
|
|
@@ -1189,7 +1298,13 @@ function buildClosePool(authority, configPda, midpriceOraclePda, curveMetaPda, c
|
|
|
1189
1298
|
isWritable: true
|
|
1190
1299
|
});
|
|
1191
1300
|
}
|
|
1192
|
-
|
|
1301
|
+
if (authorityAtaX) {
|
|
1302
|
+
keys.push({ pubkey: authorityAtaX, isSigner: false, isWritable: true });
|
|
1303
|
+
}
|
|
1304
|
+
if (authorityAtaY) {
|
|
1305
|
+
keys.push({ pubkey: authorityAtaY, isSigner: false, isWritable: true });
|
|
1306
|
+
}
|
|
1307
|
+
return new TransactionInstruction13({ programId, keys, data });
|
|
1193
1308
|
}
|
|
1194
1309
|
|
|
1195
1310
|
// src/hadron.ts
|
|
@@ -1290,7 +1405,8 @@ var Hadron = class _Hadron {
|
|
|
1290
1405
|
mintX: params.mintX,
|
|
1291
1406
|
mintY: params.mintY,
|
|
1292
1407
|
maxPrefabSlots,
|
|
1293
|
-
maxCurvePoints
|
|
1408
|
+
maxCurvePoints,
|
|
1409
|
+
authority: params.authority
|
|
1294
1410
|
};
|
|
1295
1411
|
const instructions = [];
|
|
1296
1412
|
const size = curvePrefabsSize(maxPrefabSlots, maxCurvePoints);
|
|
@@ -1633,7 +1749,7 @@ var Hadron = class _Hadron {
|
|
|
1633
1749
|
return decoded.triggers;
|
|
1634
1750
|
}
|
|
1635
1751
|
/** Build close pool instruction. */
|
|
1636
|
-
closePool(authority) {
|
|
1752
|
+
closePool(authority, authorityAtaX, authorityAtaY) {
|
|
1637
1753
|
return buildClosePool(
|
|
1638
1754
|
authority,
|
|
1639
1755
|
this.poolAddress,
|
|
@@ -1646,9 +1762,66 @@ var Hadron = class _Hadron {
|
|
|
1646
1762
|
this.config.tokenProgramX,
|
|
1647
1763
|
this.config.tokenProgramY,
|
|
1648
1764
|
this.config.spreadConfigInitialized,
|
|
1765
|
+
authorityAtaX,
|
|
1766
|
+
authorityAtaY,
|
|
1649
1767
|
this.programId
|
|
1650
1768
|
);
|
|
1651
1769
|
}
|
|
1770
|
+
// ==========================================================================
|
|
1771
|
+
// SOL Wrapping Convenience Methods
|
|
1772
|
+
// ==========================================================================
|
|
1773
|
+
/**
|
|
1774
|
+
* Build deposit instructions with automatic SOL wrapping.
|
|
1775
|
+
* If mint X or Y is native SOL, prepends wrap instructions for that side.
|
|
1776
|
+
*/
|
|
1777
|
+
depositSol(user, params) {
|
|
1778
|
+
const ixs = [];
|
|
1779
|
+
if (isNativeMint(this.config.mintX) && params.amountX > 0n) {
|
|
1780
|
+
ixs.push(...wrapSolInstructions(user, params.amountX));
|
|
1781
|
+
}
|
|
1782
|
+
if (isNativeMint(this.config.mintY) && params.amountY > 0n) {
|
|
1783
|
+
ixs.push(...wrapSolInstructions(user, params.amountY));
|
|
1784
|
+
}
|
|
1785
|
+
ixs.push(this.deposit(user, params));
|
|
1786
|
+
return ixs;
|
|
1787
|
+
}
|
|
1788
|
+
/**
|
|
1789
|
+
* Build withdraw instructions with automatic SOL unwrapping.
|
|
1790
|
+
* Creates wSOL ATA (so program can transfer into it), withdraws, then closes ATA.
|
|
1791
|
+
*/
|
|
1792
|
+
withdrawSol(user, params) {
|
|
1793
|
+
const ixs = [];
|
|
1794
|
+
const hasSol = isNativeMint(this.config.mintX) || isNativeMint(this.config.mintY);
|
|
1795
|
+
if (hasSol) {
|
|
1796
|
+
ixs.push(createWsolAtaInstruction(user));
|
|
1797
|
+
}
|
|
1798
|
+
ixs.push(this.withdraw(user, params));
|
|
1799
|
+
if (hasSol) {
|
|
1800
|
+
ixs.push(unwrapSolInstruction(user));
|
|
1801
|
+
}
|
|
1802
|
+
return ixs;
|
|
1803
|
+
}
|
|
1804
|
+
/**
|
|
1805
|
+
* Build swap instructions with automatic SOL wrapping/unwrapping.
|
|
1806
|
+
* Wraps SOL if the input side is native, unwraps if the output side is native.
|
|
1807
|
+
*/
|
|
1808
|
+
swapSol(user, params) {
|
|
1809
|
+
const ixs = [];
|
|
1810
|
+
const inputIsX = params.isX;
|
|
1811
|
+
const inputMint = inputIsX ? this.config.mintX : this.config.mintY;
|
|
1812
|
+
const outputMint = inputIsX ? this.config.mintY : this.config.mintX;
|
|
1813
|
+
if (isNativeMint(inputMint)) {
|
|
1814
|
+
ixs.push(...wrapSolInstructions(user, params.amountIn));
|
|
1815
|
+
}
|
|
1816
|
+
if (isNativeMint(outputMint)) {
|
|
1817
|
+
ixs.push(createWsolAtaInstruction(user));
|
|
1818
|
+
}
|
|
1819
|
+
ixs.push(this.swap(user, params));
|
|
1820
|
+
if (isNativeMint(outputMint)) {
|
|
1821
|
+
ixs.push(unwrapSolInstruction(user));
|
|
1822
|
+
}
|
|
1823
|
+
return ixs;
|
|
1824
|
+
}
|
|
1652
1825
|
};
|
|
1653
1826
|
|
|
1654
1827
|
// src/orderbook.ts
|
|
@@ -2212,12 +2385,12 @@ var HadronOrderbook = class _HadronOrderbook {
|
|
|
2212
2385
|
|
|
2213
2386
|
// src/helpers/token.ts
|
|
2214
2387
|
import {
|
|
2215
|
-
getAssociatedTokenAddressSync as
|
|
2388
|
+
getAssociatedTokenAddressSync as getAssociatedTokenAddressSync6,
|
|
2216
2389
|
createAssociatedTokenAccountInstruction,
|
|
2217
|
-
TOKEN_PROGRAM_ID as
|
|
2390
|
+
TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID3
|
|
2218
2391
|
} from "@solana/spl-token";
|
|
2219
|
-
async function getOrCreateAta(connection, mint, owner, payer, tokenProgram =
|
|
2220
|
-
const address =
|
|
2392
|
+
async function getOrCreateAta(connection, mint, owner, payer, tokenProgram = TOKEN_PROGRAM_ID3, allowOwnerOffCurve = false) {
|
|
2393
|
+
const address = getAssociatedTokenAddressSync6(
|
|
2221
2394
|
mint,
|
|
2222
2395
|
owner,
|
|
2223
2396
|
allowOwnerOffCurve,
|
|
@@ -2265,6 +2438,7 @@ export {
|
|
|
2265
2438
|
MAX_SETCURVE_POINTS,
|
|
2266
2439
|
MIDPRICE_ORACLE_SEED,
|
|
2267
2440
|
MIDPRICE_ORACLE_SIZE,
|
|
2441
|
+
NATIVE_MINT,
|
|
2268
2442
|
OracleMode,
|
|
2269
2443
|
POINT_DATA_SIZE,
|
|
2270
2444
|
PoolState,
|
|
@@ -2279,6 +2453,7 @@ export {
|
|
|
2279
2453
|
buildDeposit,
|
|
2280
2454
|
buildInitialize,
|
|
2281
2455
|
buildInitializeFeeConfig,
|
|
2456
|
+
buildInitializePoolFeeConfig,
|
|
2282
2457
|
buildInitializeSpreadConfig,
|
|
2283
2458
|
buildNominateAuthority,
|
|
2284
2459
|
buildRotateFeeAdmin,
|
|
@@ -2299,8 +2474,10 @@ export {
|
|
|
2299
2474
|
buildUpdateFeeConfig,
|
|
2300
2475
|
buildUpdateMidprice,
|
|
2301
2476
|
buildUpdateMidpriceAndBaseSpread,
|
|
2477
|
+
buildUpdatePoolFeeConfig,
|
|
2302
2478
|
buildUpdateSpreadConfig,
|
|
2303
2479
|
buildWithdraw,
|
|
2480
|
+
createWsolAtaInstruction,
|
|
2304
2481
|
curvePrefabsSize,
|
|
2305
2482
|
decodeActiveCurves,
|
|
2306
2483
|
decodeConfig,
|
|
@@ -2319,11 +2496,15 @@ export {
|
|
|
2319
2496
|
getFeeConfigAddress,
|
|
2320
2497
|
getMidpriceOracleAddress,
|
|
2321
2498
|
getOrCreateAta,
|
|
2499
|
+
getPoolFeeConfigAddress,
|
|
2322
2500
|
getSpreadConfigAddress,
|
|
2501
|
+
isNativeMint,
|
|
2323
2502
|
isSlotInitialized,
|
|
2324
2503
|
pctToQ32,
|
|
2325
2504
|
spreadBpsToQ32,
|
|
2326
2505
|
spreadQ32ToBps,
|
|
2327
|
-
toQ32
|
|
2506
|
+
toQ32,
|
|
2507
|
+
unwrapSolInstruction,
|
|
2508
|
+
wrapSolInstructions
|
|
2328
2509
|
};
|
|
2329
2510
|
//# sourceMappingURL=index.mjs.map
|