@hadron-fi/sdk 0.3.3 → 0.4.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 +37 -1
- package/dist/index.d.ts +37 -1
- package/dist/index.js +125 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +221 -99
- 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");
|
|
@@ -58,21 +108,21 @@ function curvePrefabsSize(maxSlots, maxPoints) {
|
|
|
58
108
|
}
|
|
59
109
|
|
|
60
110
|
// src/helpers/derive.ts
|
|
61
|
-
import { PublicKey as
|
|
62
|
-
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
|
|
111
|
+
import { PublicKey as PublicKey3 } from "@solana/web3.js";
|
|
112
|
+
import { getAssociatedTokenAddressSync as getAssociatedTokenAddressSync2 } from "@solana/spl-token";
|
|
63
113
|
function seedToBuffer(seed) {
|
|
64
114
|
const buf = Buffer.alloc(8);
|
|
65
115
|
buf.writeBigUInt64LE(seed);
|
|
66
116
|
return buf;
|
|
67
117
|
}
|
|
68
118
|
function getConfigAddress(seed, mintX, mintY, programId = HADRON_PROGRAM_ID) {
|
|
69
|
-
return
|
|
119
|
+
return PublicKey3.findProgramAddressSync(
|
|
70
120
|
[CONFIG_SEED, seedToBuffer(seed), mintX.toBuffer(), mintY.toBuffer()],
|
|
71
121
|
programId
|
|
72
122
|
);
|
|
73
123
|
}
|
|
74
124
|
function getMidpriceOracleAddress(seed, mintX, mintY, programId = HADRON_PROGRAM_ID) {
|
|
75
|
-
return
|
|
125
|
+
return PublicKey3.findProgramAddressSync(
|
|
76
126
|
[
|
|
77
127
|
MIDPRICE_ORACLE_SEED,
|
|
78
128
|
seedToBuffer(seed),
|
|
@@ -83,13 +133,13 @@ function getMidpriceOracleAddress(seed, mintX, mintY, programId = HADRON_PROGRAM
|
|
|
83
133
|
);
|
|
84
134
|
}
|
|
85
135
|
function getCurveMetaAddress(seed, mintX, mintY, programId = HADRON_PROGRAM_ID) {
|
|
86
|
-
return
|
|
136
|
+
return PublicKey3.findProgramAddressSync(
|
|
87
137
|
[CURVE_META_SEED, seedToBuffer(seed), mintX.toBuffer(), mintY.toBuffer()],
|
|
88
138
|
programId
|
|
89
139
|
);
|
|
90
140
|
}
|
|
91
141
|
function getCurvePrefabsAddress(seed, mintX, mintY, programId = HADRON_PROGRAM_ID) {
|
|
92
|
-
return
|
|
142
|
+
return PublicKey3.findProgramAddressSync(
|
|
93
143
|
[
|
|
94
144
|
CURVE_PREFABS_SEED,
|
|
95
145
|
seedToBuffer(seed),
|
|
@@ -100,7 +150,7 @@ function getCurvePrefabsAddress(seed, mintX, mintY, programId = HADRON_PROGRAM_I
|
|
|
100
150
|
);
|
|
101
151
|
}
|
|
102
152
|
function getCurveUpdatesAddress(seed, mintX, mintY, programId = HADRON_PROGRAM_ID) {
|
|
103
|
-
return
|
|
153
|
+
return PublicKey3.findProgramAddressSync(
|
|
104
154
|
[
|
|
105
155
|
CURVE_UPDATES_SEED,
|
|
106
156
|
seedToBuffer(seed),
|
|
@@ -111,10 +161,10 @@ function getCurveUpdatesAddress(seed, mintX, mintY, programId = HADRON_PROGRAM_I
|
|
|
111
161
|
);
|
|
112
162
|
}
|
|
113
163
|
function getFeeConfigAddress(programId = HADRON_PROGRAM_ID) {
|
|
114
|
-
return
|
|
164
|
+
return PublicKey3.findProgramAddressSync([FEE_CONFIG_SEED], programId);
|
|
115
165
|
}
|
|
116
166
|
function getSpreadConfigAddress(configPda, programId = HADRON_PROGRAM_ID) {
|
|
117
|
-
return
|
|
167
|
+
return PublicKey3.findProgramAddressSync(
|
|
118
168
|
[SPREAD_CONFIG_SEED, configPda.toBuffer()],
|
|
119
169
|
programId
|
|
120
170
|
);
|
|
@@ -130,13 +180,13 @@ function derivePoolAddresses(seed, mintX, mintY, tokenProgramX, tokenProgramY, p
|
|
|
130
180
|
const [curveMeta] = getCurveMetaAddress(seed, mintX, mintY, programId);
|
|
131
181
|
const [curvePrefabs] = getCurvePrefabsAddress(seed, mintX, mintY, programId);
|
|
132
182
|
const [curveUpdates] = getCurveUpdatesAddress(seed, mintX, mintY, programId);
|
|
133
|
-
const vaultX =
|
|
183
|
+
const vaultX = getAssociatedTokenAddressSync2(
|
|
134
184
|
mintX,
|
|
135
185
|
config,
|
|
136
186
|
true,
|
|
137
187
|
tokenProgramX
|
|
138
188
|
);
|
|
139
|
-
const vaultY =
|
|
189
|
+
const vaultY = getAssociatedTokenAddressSync2(
|
|
140
190
|
mintY,
|
|
141
191
|
config,
|
|
142
192
|
true,
|
|
@@ -174,7 +224,7 @@ function spreadQ32ToBps(q32) {
|
|
|
174
224
|
}
|
|
175
225
|
|
|
176
226
|
// src/accounts/index.ts
|
|
177
|
-
import { PublicKey as
|
|
227
|
+
import { PublicKey as PublicKey4 } from "@solana/web3.js";
|
|
178
228
|
|
|
179
229
|
// src/types/index.ts
|
|
180
230
|
var PoolState = /* @__PURE__ */ ((PoolState3) => {
|
|
@@ -235,15 +285,15 @@ function decodeConfig(data) {
|
|
|
235
285
|
offset += 1;
|
|
236
286
|
const seed = buf.readBigUInt64LE(offset);
|
|
237
287
|
offset += 8;
|
|
238
|
-
const authority = new
|
|
288
|
+
const authority = new PublicKey4(buf.subarray(offset, offset + 32));
|
|
239
289
|
offset += 32;
|
|
240
|
-
const mintX = new
|
|
290
|
+
const mintX = new PublicKey4(buf.subarray(offset, offset + 32));
|
|
241
291
|
offset += 32;
|
|
242
|
-
const mintY = new
|
|
292
|
+
const mintY = new PublicKey4(buf.subarray(offset, offset + 32));
|
|
243
293
|
offset += 32;
|
|
244
294
|
const configBump = buf.readUInt8(offset);
|
|
245
295
|
offset += 1;
|
|
246
|
-
const curveMeta = new
|
|
296
|
+
const curveMeta = new PublicKey4(buf.subarray(offset, offset + 32));
|
|
247
297
|
offset += 32;
|
|
248
298
|
const spreadConfigInitialized = buf.readUInt8(offset) !== 0;
|
|
249
299
|
offset += 1;
|
|
@@ -252,13 +302,13 @@ function decodeConfig(data) {
|
|
|
252
302
|
const oracleMode = buf.readUInt8(offset);
|
|
253
303
|
offset += 1;
|
|
254
304
|
offset += 3;
|
|
255
|
-
const pendingAuthority = new
|
|
305
|
+
const pendingAuthority = new PublicKey4(buf.subarray(offset, offset + 32));
|
|
256
306
|
offset += 32;
|
|
257
307
|
const nominationExpiry = buf.readBigUInt64LE(offset);
|
|
258
308
|
offset += 8;
|
|
259
|
-
const tokenProgramX = new
|
|
309
|
+
const tokenProgramX = new PublicKey4(buf.subarray(offset, offset + 32));
|
|
260
310
|
offset += 32;
|
|
261
|
-
const tokenProgramY = new
|
|
311
|
+
const tokenProgramY = new PublicKey4(buf.subarray(offset, offset + 32));
|
|
262
312
|
return {
|
|
263
313
|
state,
|
|
264
314
|
seed,
|
|
@@ -278,7 +328,7 @@ function decodeConfig(data) {
|
|
|
278
328
|
}
|
|
279
329
|
function decodeMidpriceOracle(data) {
|
|
280
330
|
const buf = Buffer.from(data);
|
|
281
|
-
const authority = new
|
|
331
|
+
const authority = new PublicKey4(buf.subarray(0, 32));
|
|
282
332
|
const sequence = buf.readBigUInt64LE(32);
|
|
283
333
|
const midpriceQ32 = buf.readBigUInt64LE(40);
|
|
284
334
|
const spreadFactorQ32 = buf.readBigUInt64LE(48);
|
|
@@ -288,7 +338,7 @@ function decodeMidpriceOracle(data) {
|
|
|
288
338
|
function decodeCurveMeta(data) {
|
|
289
339
|
const buf = Buffer.from(data);
|
|
290
340
|
return {
|
|
291
|
-
authority: new
|
|
341
|
+
authority: new PublicKey4(buf.subarray(0, 32)),
|
|
292
342
|
activePriceBidSlot: buf.readUInt8(32),
|
|
293
343
|
activePriceAskSlot: buf.readUInt8(33),
|
|
294
344
|
activeRiskBidSlot: buf.readUInt8(34),
|
|
@@ -311,8 +361,8 @@ function decodeFeeConfig(data) {
|
|
|
311
361
|
feePpm: buf.readUInt32LE(1),
|
|
312
362
|
bump: buf.readUInt8(5),
|
|
313
363
|
// skip 2 bytes padding
|
|
314
|
-
feeAdmin: new
|
|
315
|
-
feeRecipient: new
|
|
364
|
+
feeAdmin: new PublicKey4(buf.subarray(8, 40)),
|
|
365
|
+
feeRecipient: new PublicKey4(buf.subarray(40, 72))
|
|
316
366
|
};
|
|
317
367
|
}
|
|
318
368
|
var SPREAD_TRIGGER_LEN = 40;
|
|
@@ -321,13 +371,13 @@ function decodeSpreadConfig(data) {
|
|
|
321
371
|
const initialized = buf.readUInt8(0) !== 0;
|
|
322
372
|
const bump = buf.readUInt8(1);
|
|
323
373
|
const numTriggers = buf.readUInt8(2);
|
|
324
|
-
const admin = new
|
|
325
|
-
const config = new
|
|
374
|
+
const admin = new PublicKey4(buf.subarray(8, 40));
|
|
375
|
+
const config = new PublicKey4(buf.subarray(40, 72));
|
|
326
376
|
const triggers = [];
|
|
327
377
|
const triggersStart = 72;
|
|
328
378
|
for (let i = 0; i < numTriggers; i++) {
|
|
329
379
|
const off = triggersStart + i * SPREAD_TRIGGER_LEN;
|
|
330
|
-
const account = new
|
|
380
|
+
const account = new PublicKey4(buf.subarray(off, off + 32));
|
|
331
381
|
const spreadBps = buf.readUInt16LE(off + 32);
|
|
332
382
|
triggers.push({ account, spreadBps });
|
|
333
383
|
}
|
|
@@ -336,9 +386,9 @@ function decodeSpreadConfig(data) {
|
|
|
336
386
|
function decodeCurveUpdates(data) {
|
|
337
387
|
const buf = Buffer.from(data);
|
|
338
388
|
let offset = 0;
|
|
339
|
-
const authority = new
|
|
389
|
+
const authority = new PublicKey4(buf.subarray(offset, offset + 32));
|
|
340
390
|
offset += 32;
|
|
341
|
-
const curveMeta = new
|
|
391
|
+
const curveMeta = new PublicKey4(buf.subarray(offset, offset + 32));
|
|
342
392
|
offset += 32;
|
|
343
393
|
const numOps = buf.readUInt8(offset);
|
|
344
394
|
offset += 1;
|
|
@@ -416,16 +466,16 @@ function decodeActiveCurves(prefabsData, meta) {
|
|
|
416
466
|
|
|
417
467
|
// src/instructions/initialize.ts
|
|
418
468
|
import {
|
|
419
|
-
PublicKey as
|
|
420
|
-
SystemProgram,
|
|
421
|
-
TransactionInstruction
|
|
469
|
+
PublicKey as PublicKey5,
|
|
470
|
+
SystemProgram as SystemProgram2,
|
|
471
|
+
TransactionInstruction as TransactionInstruction2
|
|
422
472
|
} from "@solana/web3.js";
|
|
423
|
-
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
|
473
|
+
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID2 } from "@solana/spl-token";
|
|
424
474
|
function buildInitialize(payer, params, programId = HADRON_PROGRAM_ID) {
|
|
425
475
|
const seed = params.seed;
|
|
426
476
|
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 ??
|
|
477
|
+
const tokenProgramX = params.tokenProgramX ?? TOKEN_PROGRAM_ID2;
|
|
478
|
+
const tokenProgramY = params.tokenProgramY ?? TOKEN_PROGRAM_ID2;
|
|
429
479
|
const maxPrefabSlots = params.maxPrefabSlots ?? DEFAULT_MAX_PREFAB_SLOTS;
|
|
430
480
|
const maxCurvePoints = params.maxCurvePoints ?? DEFAULT_MAX_CURVE_POINTS;
|
|
431
481
|
const oracleMode = params.oracleMode ?? 0;
|
|
@@ -463,7 +513,7 @@ function buildInitialize(payer, params, programId = HADRON_PROGRAM_ID) {
|
|
|
463
513
|
offset += 1;
|
|
464
514
|
data.writeUInt8(maxCurvePoints, offset);
|
|
465
515
|
}
|
|
466
|
-
return new
|
|
516
|
+
return new TransactionInstruction2({
|
|
467
517
|
programId,
|
|
468
518
|
keys: [
|
|
469
519
|
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
@@ -479,7 +529,7 @@ function buildInitialize(payer, params, programId = HADRON_PROGRAM_ID) {
|
|
|
479
529
|
isSigner: false,
|
|
480
530
|
isWritable: false
|
|
481
531
|
},
|
|
482
|
-
{ pubkey:
|
|
532
|
+
{ pubkey: SystemProgram2.programId, isSigner: false, isWritable: false },
|
|
483
533
|
{ pubkey: addrs.midpriceOracle, isSigner: false, isWritable: true },
|
|
484
534
|
{ pubkey: addrs.curveMeta, isSigner: false, isWritable: true },
|
|
485
535
|
{ pubkey: addrs.curvePrefabs, isSigner: false, isWritable: true },
|
|
@@ -504,7 +554,7 @@ function buildAllocateCurvePrefabs(payer, params, programId = HADRON_PROGRAM_ID)
|
|
|
504
554
|
data.writeUInt8(maxPrefabSlots, offset);
|
|
505
555
|
offset += 1;
|
|
506
556
|
data.writeUInt8(maxCurvePoints, offset);
|
|
507
|
-
const [curvePrefabsPda] =
|
|
557
|
+
const [curvePrefabsPda] = PublicKey5.findProgramAddressSync(
|
|
508
558
|
[
|
|
509
559
|
Buffer.from("hadron-curve-prefabs"),
|
|
510
560
|
(() => {
|
|
@@ -517,20 +567,20 @@ function buildAllocateCurvePrefabs(payer, params, programId = HADRON_PROGRAM_ID)
|
|
|
517
567
|
],
|
|
518
568
|
programId
|
|
519
569
|
);
|
|
520
|
-
return new
|
|
570
|
+
return new TransactionInstruction2({
|
|
521
571
|
programId,
|
|
522
572
|
keys: [
|
|
523
573
|
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
524
574
|
{ pubkey: curvePrefabsPda, isSigner: false, isWritable: true },
|
|
525
|
-
{ pubkey:
|
|
575
|
+
{ pubkey: SystemProgram2.programId, isSigner: false, isWritable: false }
|
|
526
576
|
],
|
|
527
577
|
data
|
|
528
578
|
});
|
|
529
579
|
}
|
|
530
580
|
|
|
531
581
|
// src/instructions/deposit.ts
|
|
532
|
-
import { TransactionInstruction as
|
|
533
|
-
import { getAssociatedTokenAddressSync as
|
|
582
|
+
import { TransactionInstruction as TransactionInstruction3 } from "@solana/web3.js";
|
|
583
|
+
import { getAssociatedTokenAddressSync as getAssociatedTokenAddressSync3 } from "@solana/spl-token";
|
|
534
584
|
function buildDeposit(user, configPda, mintX, mintY, tokenProgramX, tokenProgramY, params, programId = HADRON_PROGRAM_ID) {
|
|
535
585
|
const data = Buffer.alloc(1 + 8 + 8 + 8);
|
|
536
586
|
let offset = 0;
|
|
@@ -542,11 +592,11 @@ function buildDeposit(user, configPda, mintX, mintY, tokenProgramX, tokenProgram
|
|
|
542
592
|
offset += 8;
|
|
543
593
|
const exp = params.expiration ?? Math.floor(Date.now() / 1e3) + 3600;
|
|
544
594
|
data.writeBigInt64LE(BigInt(exp), offset);
|
|
545
|
-
const userX =
|
|
546
|
-
const userY =
|
|
547
|
-
const vaultX =
|
|
548
|
-
const vaultY =
|
|
549
|
-
return new
|
|
595
|
+
const userX = getAssociatedTokenAddressSync3(mintX, user, false, tokenProgramX);
|
|
596
|
+
const userY = getAssociatedTokenAddressSync3(mintY, user, false, tokenProgramY);
|
|
597
|
+
const vaultX = getAssociatedTokenAddressSync3(mintX, configPda, true, tokenProgramX);
|
|
598
|
+
const vaultY = getAssociatedTokenAddressSync3(mintY, configPda, true, tokenProgramY);
|
|
599
|
+
return new TransactionInstruction3({
|
|
550
600
|
programId,
|
|
551
601
|
keys: [
|
|
552
602
|
{ pubkey: user, isSigner: true, isWritable: false },
|
|
@@ -563,8 +613,8 @@ function buildDeposit(user, configPda, mintX, mintY, tokenProgramX, tokenProgram
|
|
|
563
613
|
}
|
|
564
614
|
|
|
565
615
|
// src/instructions/withdraw.ts
|
|
566
|
-
import { TransactionInstruction as
|
|
567
|
-
import { getAssociatedTokenAddressSync as
|
|
616
|
+
import { TransactionInstruction as TransactionInstruction4 } from "@solana/web3.js";
|
|
617
|
+
import { getAssociatedTokenAddressSync as getAssociatedTokenAddressSync4 } from "@solana/spl-token";
|
|
568
618
|
function buildWithdraw(user, configPda, mintX, mintY, tokenProgramX, tokenProgramY, params, programId = HADRON_PROGRAM_ID) {
|
|
569
619
|
const data = Buffer.alloc(1 + 8 + 8 + 8);
|
|
570
620
|
let offset = 0;
|
|
@@ -576,11 +626,11 @@ function buildWithdraw(user, configPda, mintX, mintY, tokenProgramX, tokenProgra
|
|
|
576
626
|
offset += 8;
|
|
577
627
|
const exp = params.expiration ?? Math.floor(Date.now() / 1e3) + 3600;
|
|
578
628
|
data.writeBigInt64LE(BigInt(exp), offset);
|
|
579
|
-
const userX =
|
|
580
|
-
const userY =
|
|
581
|
-
const vaultX =
|
|
582
|
-
const vaultY =
|
|
583
|
-
return new
|
|
629
|
+
const userX = getAssociatedTokenAddressSync4(mintX, user, false, tokenProgramX);
|
|
630
|
+
const userY = getAssociatedTokenAddressSync4(mintY, user, false, tokenProgramY);
|
|
631
|
+
const vaultX = getAssociatedTokenAddressSync4(mintX, configPda, true, tokenProgramX);
|
|
632
|
+
const vaultY = getAssociatedTokenAddressSync4(mintY, configPda, true, tokenProgramY);
|
|
633
|
+
return new TransactionInstruction4({
|
|
584
634
|
programId,
|
|
585
635
|
keys: [
|
|
586
636
|
{ pubkey: user, isSigner: true, isWritable: false },
|
|
@@ -600,9 +650,9 @@ function buildWithdraw(user, configPda, mintX, mintY, tokenProgramX, tokenProgra
|
|
|
600
650
|
import {
|
|
601
651
|
SYSVAR_CLOCK_PUBKEY,
|
|
602
652
|
SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
603
|
-
TransactionInstruction as
|
|
653
|
+
TransactionInstruction as TransactionInstruction5
|
|
604
654
|
} from "@solana/web3.js";
|
|
605
|
-
import { getAssociatedTokenAddressSync as
|
|
655
|
+
import { getAssociatedTokenAddressSync as getAssociatedTokenAddressSync5 } from "@solana/spl-token";
|
|
606
656
|
function buildSwapExactIn(user, poolAddresses, mintX, mintY, tokenProgramX, tokenProgramY, params, programId = HADRON_PROGRAM_ID, spreadConfigInitialized = false) {
|
|
607
657
|
const data = Buffer.alloc(1 + 1 + 8 + 8 + 8);
|
|
608
658
|
let offset = 0;
|
|
@@ -616,13 +666,13 @@ function buildSwapExactIn(user, poolAddresses, mintX, mintY, tokenProgramX, toke
|
|
|
616
666
|
offset += 8;
|
|
617
667
|
const exp = params.expiration ?? Math.floor(Date.now() / 1e3) + 3600;
|
|
618
668
|
data.writeBigInt64LE(BigInt(exp), offset);
|
|
619
|
-
const userX =
|
|
620
|
-
const userY =
|
|
669
|
+
const userX = getAssociatedTokenAddressSync5(mintX, user, false, tokenProgramX);
|
|
670
|
+
const userY = getAssociatedTokenAddressSync5(mintY, user, false, tokenProgramY);
|
|
621
671
|
const [userSource, vaultSource, vaultDest, userDest] = params.isX ? [userX, poolAddresses.vaultX, poolAddresses.vaultY, userY] : [userY, poolAddresses.vaultY, poolAddresses.vaultX, userX];
|
|
622
672
|
const [feeConfigPda] = getFeeConfigAddress(programId);
|
|
623
673
|
const inputMint = params.isX ? mintX : mintY;
|
|
624
674
|
const inputMintProgram = params.isX ? tokenProgramX : tokenProgramY;
|
|
625
|
-
const feeRecipientAta =
|
|
675
|
+
const feeRecipientAta = getAssociatedTokenAddressSync5(
|
|
626
676
|
inputMint,
|
|
627
677
|
params.feeRecipient,
|
|
628
678
|
false,
|
|
@@ -669,7 +719,7 @@ function buildSwapExactIn(user, poolAddresses, mintX, mintY, tokenProgramX, toke
|
|
|
669
719
|
{ pubkey: SYSVAR_INSTRUCTIONS_PUBKEY, isSigner: false, isWritable: false }
|
|
670
720
|
);
|
|
671
721
|
}
|
|
672
|
-
return new
|
|
722
|
+
return new TransactionInstruction5({
|
|
673
723
|
programId,
|
|
674
724
|
keys,
|
|
675
725
|
data
|
|
@@ -677,7 +727,7 @@ function buildSwapExactIn(user, poolAddresses, mintX, mintY, tokenProgramX, toke
|
|
|
677
727
|
}
|
|
678
728
|
|
|
679
729
|
// src/instructions/setCurve.ts
|
|
680
|
-
import { TransactionInstruction as
|
|
730
|
+
import { TransactionInstruction as TransactionInstruction6 } from "@solana/web3.js";
|
|
681
731
|
function interpolationToByte(interp) {
|
|
682
732
|
return interp;
|
|
683
733
|
}
|
|
@@ -713,7 +763,7 @@ function buildSetCurve(authority, curveMetaPda, curvePrefabsPda, params, program
|
|
|
713
763
|
Buffer.from(params_).copy(data, offset, 0, 4);
|
|
714
764
|
offset += 4;
|
|
715
765
|
}
|
|
716
|
-
return new
|
|
766
|
+
return new TransactionInstruction6({
|
|
717
767
|
programId,
|
|
718
768
|
keys: [
|
|
719
769
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -760,7 +810,7 @@ function buildSetRiskCurve(authority, curveMetaPda, curvePrefabsPda, params, pro
|
|
|
760
810
|
Buffer.from(params_).copy(data, offset, 0, 4);
|
|
761
811
|
offset += 4;
|
|
762
812
|
}
|
|
763
|
-
return new
|
|
813
|
+
return new TransactionInstruction6({
|
|
764
814
|
programId,
|
|
765
815
|
keys: [
|
|
766
816
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -806,7 +856,7 @@ function buildSetRiskCurveAbsolute(authority, curveMetaPda, curvePrefabsPda, par
|
|
|
806
856
|
Buffer.from(params_).copy(data, offset, 0, 4);
|
|
807
857
|
offset += 4;
|
|
808
858
|
}
|
|
809
|
-
return new
|
|
859
|
+
return new TransactionInstruction6({
|
|
810
860
|
programId,
|
|
811
861
|
keys: [
|
|
812
862
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -835,14 +885,14 @@ function buildSetRiskCurveAbsoluteBoth(authority, curveMetaPda, curvePrefabsPda,
|
|
|
835
885
|
// src/instructions/oracle.ts
|
|
836
886
|
import {
|
|
837
887
|
SYSVAR_CLOCK_PUBKEY as SYSVAR_CLOCK_PUBKEY2,
|
|
838
|
-
TransactionInstruction as
|
|
888
|
+
TransactionInstruction as TransactionInstruction7
|
|
839
889
|
} from "@solana/web3.js";
|
|
840
890
|
function buildUpdateMidprice(authority, midpriceOraclePda, params, programId = HADRON_PROGRAM_ID) {
|
|
841
891
|
const data = Buffer.alloc(1 + 8 + 8);
|
|
842
892
|
data.writeUInt8(Discriminator.UpdateMidprice, 0);
|
|
843
893
|
data.writeBigUInt64LE(params.sequence ?? 0n, 1);
|
|
844
894
|
data.writeBigUInt64LE(params.midpriceQ32, 9);
|
|
845
|
-
return new
|
|
895
|
+
return new TransactionInstruction7({
|
|
846
896
|
programId,
|
|
847
897
|
keys: [
|
|
848
898
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -857,7 +907,7 @@ function buildUpdateBaseSpread(authority, midpriceOraclePda, params, programId =
|
|
|
857
907
|
data.writeUInt8(Discriminator.UpdateBaseSpread, 0);
|
|
858
908
|
data.writeBigUInt64LE(params.sequence ?? 0n, 1);
|
|
859
909
|
data.writeBigUInt64LE(params.spreadFactorQ32, 9);
|
|
860
|
-
return new
|
|
910
|
+
return new TransactionInstruction7({
|
|
861
911
|
programId,
|
|
862
912
|
keys: [
|
|
863
913
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -873,7 +923,7 @@ function buildUpdateMidpriceAndBaseSpread(authority, midpriceOraclePda, params,
|
|
|
873
923
|
data.writeBigUInt64LE(params.sequence ?? 0n, 1);
|
|
874
924
|
data.writeBigUInt64LE(params.midpriceQ32, 9);
|
|
875
925
|
data.writeBigUInt64LE(params.spreadFactorQ32, 17);
|
|
876
|
-
return new
|
|
926
|
+
return new TransactionInstruction7({
|
|
877
927
|
programId,
|
|
878
928
|
keys: [
|
|
879
929
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -885,13 +935,13 @@ function buildUpdateMidpriceAndBaseSpread(authority, midpriceOraclePda, params,
|
|
|
885
935
|
}
|
|
886
936
|
|
|
887
937
|
// src/instructions/switchCurve.ts
|
|
888
|
-
import { TransactionInstruction as
|
|
938
|
+
import { TransactionInstruction as TransactionInstruction8 } from "@solana/web3.js";
|
|
889
939
|
function buildSwitchPriceCurve(authority, curveMetaPda, params, programId = HADRON_PROGRAM_ID) {
|
|
890
940
|
const data = Buffer.alloc(1 + 1 + 1);
|
|
891
941
|
data.writeUInt8(Discriminator.SwitchPriceCurve, 0);
|
|
892
942
|
data.writeUInt8(params.side, 1);
|
|
893
943
|
data.writeUInt8(params.slot, 2);
|
|
894
|
-
return new
|
|
944
|
+
return new TransactionInstruction8({
|
|
895
945
|
programId,
|
|
896
946
|
keys: [
|
|
897
947
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -905,7 +955,7 @@ function buildSwitchRiskCurve(authority, curveMetaPda, params, programId = HADRO
|
|
|
905
955
|
data.writeUInt8(Discriminator.SwitchRiskCurve, 0);
|
|
906
956
|
data.writeUInt8(params.side, 1);
|
|
907
957
|
data.writeUInt8(params.slot, 2);
|
|
908
|
-
return new
|
|
958
|
+
return new TransactionInstruction8({
|
|
909
959
|
programId,
|
|
910
960
|
keys: [
|
|
911
961
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -916,7 +966,7 @@ function buildSwitchRiskCurve(authority, curveMetaPda, params, programId = HADRO
|
|
|
916
966
|
}
|
|
917
967
|
|
|
918
968
|
// src/instructions/curveUpdates.ts
|
|
919
|
-
import { TransactionInstruction as
|
|
969
|
+
import { TransactionInstruction as TransactionInstruction9 } from "@solana/web3.js";
|
|
920
970
|
function buildSubmitCurveUpdates(authority, curveUpdatesPda, ops, programId = HADRON_PROGRAM_ID) {
|
|
921
971
|
const data = Buffer.alloc(1 + 1 + ops.length * CURVE_UPDATE_OP_SIZE);
|
|
922
972
|
let offset = 0;
|
|
@@ -941,7 +991,7 @@ function buildSubmitCurveUpdates(authority, curveUpdatesPda, ops, programId = HA
|
|
|
941
991
|
Buffer.from(params).copy(data, offset, 0, 4);
|
|
942
992
|
offset += 4;
|
|
943
993
|
}
|
|
944
|
-
return new
|
|
994
|
+
return new TransactionInstruction9({
|
|
945
995
|
programId,
|
|
946
996
|
keys: [
|
|
947
997
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -953,7 +1003,7 @@ function buildSubmitCurveUpdates(authority, curveUpdatesPda, ops, programId = HA
|
|
|
953
1003
|
function buildApplyCurveUpdates(authority, curveMetaPda, curvePrefabsPda, curveUpdatesPda, programId = HADRON_PROGRAM_ID) {
|
|
954
1004
|
const data = Buffer.alloc(1);
|
|
955
1005
|
data.writeUInt8(Discriminator.ApplyCurveUpdates, 0);
|
|
956
|
-
return new
|
|
1006
|
+
return new TransactionInstruction9({
|
|
957
1007
|
programId,
|
|
958
1008
|
keys: [
|
|
959
1009
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -968,7 +1018,7 @@ function buildApplyCurveUpdates(authority, curveMetaPda, curvePrefabsPda, curveU
|
|
|
968
1018
|
// src/instructions/authority.ts
|
|
969
1019
|
import {
|
|
970
1020
|
SYSVAR_CLOCK_PUBKEY as SYSVAR_CLOCK_PUBKEY3,
|
|
971
|
-
TransactionInstruction as
|
|
1021
|
+
TransactionInstruction as TransactionInstruction10
|
|
972
1022
|
} from "@solana/web3.js";
|
|
973
1023
|
function buildNominateAuthority(authority, configPda, params, programId = HADRON_PROGRAM_ID) {
|
|
974
1024
|
const data = Buffer.alloc(1 + 32 + 8);
|
|
@@ -978,7 +1028,7 @@ function buildNominateAuthority(authority, configPda, params, programId = HADRON
|
|
|
978
1028
|
params.newAuthority.toBuffer().copy(data, offset);
|
|
979
1029
|
offset += 32;
|
|
980
1030
|
data.writeBigUInt64LE(params.expirySlot, offset);
|
|
981
|
-
return new
|
|
1031
|
+
return new TransactionInstruction10({
|
|
982
1032
|
programId,
|
|
983
1033
|
keys: [
|
|
984
1034
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -991,7 +1041,7 @@ function buildNominateAuthority(authority, configPda, params, programId = HADRON
|
|
|
991
1041
|
function buildAcceptAuthority(newAuthority, configPda, programId = HADRON_PROGRAM_ID) {
|
|
992
1042
|
const data = Buffer.alloc(1);
|
|
993
1043
|
data.writeUInt8(Discriminator.AcceptAuthority, 0);
|
|
994
|
-
return new
|
|
1044
|
+
return new TransactionInstruction10({
|
|
995
1045
|
programId,
|
|
996
1046
|
keys: [
|
|
997
1047
|
{ pubkey: newAuthority, isSigner: true, isWritable: false },
|
|
@@ -1019,7 +1069,7 @@ function buildSetQuotingAuthority(authority, configPda, oraclePda, curveMetaPda,
|
|
|
1019
1069
|
isWritable: true
|
|
1020
1070
|
});
|
|
1021
1071
|
}
|
|
1022
|
-
return new
|
|
1072
|
+
return new TransactionInstruction10({
|
|
1023
1073
|
programId,
|
|
1024
1074
|
keys,
|
|
1025
1075
|
data
|
|
@@ -1028,8 +1078,8 @@ function buildSetQuotingAuthority(authority, configPda, oraclePda, curveMetaPda,
|
|
|
1028
1078
|
|
|
1029
1079
|
// src/instructions/feeConfig.ts
|
|
1030
1080
|
import {
|
|
1031
|
-
SystemProgram as
|
|
1032
|
-
TransactionInstruction as
|
|
1081
|
+
SystemProgram as SystemProgram3,
|
|
1082
|
+
TransactionInstruction as TransactionInstruction11
|
|
1033
1083
|
} from "@solana/web3.js";
|
|
1034
1084
|
function buildInitializeFeeConfig(payer, authority, params, programId = HADRON_PROGRAM_ID) {
|
|
1035
1085
|
const [feeConfigPda] = getFeeConfigAddress(programId);
|
|
@@ -1042,13 +1092,13 @@ function buildInitializeFeeConfig(payer, authority, params, programId = HADRON_P
|
|
|
1042
1092
|
params.feeAdmin.toBuffer().copy(data, offset);
|
|
1043
1093
|
offset += 32;
|
|
1044
1094
|
params.feeRecipient.toBuffer().copy(data, offset);
|
|
1045
|
-
return new
|
|
1095
|
+
return new TransactionInstruction11({
|
|
1046
1096
|
programId,
|
|
1047
1097
|
keys: [
|
|
1048
1098
|
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
1049
1099
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
1050
1100
|
{ pubkey: feeConfigPda, isSigner: false, isWritable: true },
|
|
1051
|
-
{ pubkey:
|
|
1101
|
+
{ pubkey: SystemProgram3.programId, isSigner: false, isWritable: false }
|
|
1052
1102
|
],
|
|
1053
1103
|
data
|
|
1054
1104
|
});
|
|
@@ -1064,7 +1114,7 @@ function buildUpdateFeeConfig(feeAdmin, params, programId = HADRON_PROGRAM_ID) {
|
|
|
1064
1114
|
if (params.feeRecipient) {
|
|
1065
1115
|
params.feeRecipient.toBuffer().copy(data, offset);
|
|
1066
1116
|
}
|
|
1067
|
-
return new
|
|
1117
|
+
return new TransactionInstruction11({
|
|
1068
1118
|
programId,
|
|
1069
1119
|
keys: [
|
|
1070
1120
|
{ pubkey: feeAdmin, isSigner: true, isWritable: false },
|
|
@@ -1078,7 +1128,7 @@ function buildRotateFeeAdmin(feeAdmin, params, programId = HADRON_PROGRAM_ID) {
|
|
|
1078
1128
|
const data = Buffer.alloc(1 + 32);
|
|
1079
1129
|
data.writeUInt8(Discriminator.RotateFeeAdmin, 0);
|
|
1080
1130
|
params.newFeeAdmin.toBuffer().copy(data, 1);
|
|
1081
|
-
return new
|
|
1131
|
+
return new TransactionInstruction11({
|
|
1082
1132
|
programId,
|
|
1083
1133
|
keys: [
|
|
1084
1134
|
{ pubkey: feeAdmin, isSigner: true, isWritable: false },
|
|
@@ -1090,22 +1140,22 @@ function buildRotateFeeAdmin(feeAdmin, params, programId = HADRON_PROGRAM_ID) {
|
|
|
1090
1140
|
|
|
1091
1141
|
// src/instructions/spreadConfig.ts
|
|
1092
1142
|
import {
|
|
1093
|
-
SystemProgram as
|
|
1094
|
-
TransactionInstruction as
|
|
1143
|
+
SystemProgram as SystemProgram4,
|
|
1144
|
+
TransactionInstruction as TransactionInstruction12
|
|
1095
1145
|
} from "@solana/web3.js";
|
|
1096
1146
|
function buildInitializeSpreadConfig(payer, authority, configPda, params, programId = HADRON_PROGRAM_ID) {
|
|
1097
1147
|
const [spreadConfigPda] = getSpreadConfigAddress(configPda, programId);
|
|
1098
1148
|
const data = Buffer.alloc(1 + 32);
|
|
1099
1149
|
data.writeUInt8(Discriminator.InitializeSpreadConfig, 0);
|
|
1100
1150
|
params.admin.toBuffer().copy(data, 1);
|
|
1101
|
-
return new
|
|
1151
|
+
return new TransactionInstruction12({
|
|
1102
1152
|
programId,
|
|
1103
1153
|
keys: [
|
|
1104
1154
|
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
1105
1155
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
1106
1156
|
{ pubkey: configPda, isSigner: false, isWritable: true },
|
|
1107
1157
|
{ pubkey: spreadConfigPda, isSigner: false, isWritable: true },
|
|
1108
|
-
{ pubkey:
|
|
1158
|
+
{ pubkey: SystemProgram4.programId, isSigner: false, isWritable: false }
|
|
1109
1159
|
],
|
|
1110
1160
|
data
|
|
1111
1161
|
});
|
|
@@ -1125,7 +1175,7 @@ function buildUpdateSpreadConfig(admin, configPda, params, programId = HADRON_PR
|
|
|
1125
1175
|
data.writeUInt16LE(t.spreadBps, offset);
|
|
1126
1176
|
offset += 2;
|
|
1127
1177
|
}
|
|
1128
|
-
return new
|
|
1178
|
+
return new TransactionInstruction12({
|
|
1129
1179
|
programId,
|
|
1130
1180
|
keys: [
|
|
1131
1181
|
{ pubkey: admin, isSigner: true, isWritable: false },
|
|
@@ -1138,13 +1188,13 @@ function buildUpdateSpreadConfig(admin, configPda, params, programId = HADRON_PR
|
|
|
1138
1188
|
|
|
1139
1189
|
// src/instructions/poolState.ts
|
|
1140
1190
|
import {
|
|
1141
|
-
TransactionInstruction as
|
|
1191
|
+
TransactionInstruction as TransactionInstruction13
|
|
1142
1192
|
} from "@solana/web3.js";
|
|
1143
1193
|
function buildSetPoolState(authority, configPda, params, programId = HADRON_PROGRAM_ID) {
|
|
1144
1194
|
const data = Buffer.alloc(1 + 1);
|
|
1145
1195
|
data.writeUInt8(Discriminator.SetPoolState, 0);
|
|
1146
1196
|
data.writeUInt8(params.newState, 1);
|
|
1147
|
-
return new
|
|
1197
|
+
return new TransactionInstruction13({
|
|
1148
1198
|
programId,
|
|
1149
1199
|
keys: [
|
|
1150
1200
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -1157,7 +1207,7 @@ function buildUpdateDeltaStaleness(authority, configPda, params, programId = HAD
|
|
|
1157
1207
|
const data = Buffer.alloc(1 + 1);
|
|
1158
1208
|
data.writeUInt8(Discriminator.UpdateDeltaStaleness, 0);
|
|
1159
1209
|
data.writeUInt8(params.deltaStaleness, 1);
|
|
1160
|
-
return new
|
|
1210
|
+
return new TransactionInstruction13({
|
|
1161
1211
|
programId,
|
|
1162
1212
|
keys: [
|
|
1163
1213
|
{ pubkey: authority, isSigner: true, isWritable: false },
|
|
@@ -1189,7 +1239,7 @@ function buildClosePool(authority, configPda, midpriceOraclePda, curveMetaPda, c
|
|
|
1189
1239
|
isWritable: true
|
|
1190
1240
|
});
|
|
1191
1241
|
}
|
|
1192
|
-
return new
|
|
1242
|
+
return new TransactionInstruction13({ programId, keys, data });
|
|
1193
1243
|
}
|
|
1194
1244
|
|
|
1195
1245
|
// src/hadron.ts
|
|
@@ -1542,6 +1592,18 @@ var Hadron = class _Hadron {
|
|
|
1542
1592
|
this.programId
|
|
1543
1593
|
);
|
|
1544
1594
|
}
|
|
1595
|
+
/** Build set quoting authority instruction. */
|
|
1596
|
+
setQuotingAuthority(authority, params) {
|
|
1597
|
+
return buildSetQuotingAuthority(
|
|
1598
|
+
authority,
|
|
1599
|
+
this.poolAddress,
|
|
1600
|
+
this.addresses.midpriceOracle,
|
|
1601
|
+
this.addresses.curveMeta,
|
|
1602
|
+
this.addresses.curveUpdates,
|
|
1603
|
+
params,
|
|
1604
|
+
this.programId
|
|
1605
|
+
);
|
|
1606
|
+
}
|
|
1545
1607
|
/** Build set pool state instruction. */
|
|
1546
1608
|
setPoolState(authority, params) {
|
|
1547
1609
|
return buildSetPoolState(
|
|
@@ -1637,6 +1699,61 @@ var Hadron = class _Hadron {
|
|
|
1637
1699
|
this.programId
|
|
1638
1700
|
);
|
|
1639
1701
|
}
|
|
1702
|
+
// ==========================================================================
|
|
1703
|
+
// SOL Wrapping Convenience Methods
|
|
1704
|
+
// ==========================================================================
|
|
1705
|
+
/**
|
|
1706
|
+
* Build deposit instructions with automatic SOL wrapping.
|
|
1707
|
+
* If mint X or Y is native SOL, prepends wrap instructions for that side.
|
|
1708
|
+
*/
|
|
1709
|
+
depositSol(user, params) {
|
|
1710
|
+
const ixs = [];
|
|
1711
|
+
if (isNativeMint(this.config.mintX) && params.amountX > 0n) {
|
|
1712
|
+
ixs.push(...wrapSolInstructions(user, params.amountX));
|
|
1713
|
+
}
|
|
1714
|
+
if (isNativeMint(this.config.mintY) && params.amountY > 0n) {
|
|
1715
|
+
ixs.push(...wrapSolInstructions(user, params.amountY));
|
|
1716
|
+
}
|
|
1717
|
+
ixs.push(this.deposit(user, params));
|
|
1718
|
+
return ixs;
|
|
1719
|
+
}
|
|
1720
|
+
/**
|
|
1721
|
+
* Build withdraw instructions with automatic SOL unwrapping.
|
|
1722
|
+
* Creates wSOL ATA (so program can transfer into it), withdraws, then closes ATA.
|
|
1723
|
+
*/
|
|
1724
|
+
withdrawSol(user, params) {
|
|
1725
|
+
const ixs = [];
|
|
1726
|
+
const hasSol = isNativeMint(this.config.mintX) || isNativeMint(this.config.mintY);
|
|
1727
|
+
if (hasSol) {
|
|
1728
|
+
ixs.push(createWsolAtaInstruction(user));
|
|
1729
|
+
}
|
|
1730
|
+
ixs.push(this.withdraw(user, params));
|
|
1731
|
+
if (hasSol) {
|
|
1732
|
+
ixs.push(unwrapSolInstruction(user));
|
|
1733
|
+
}
|
|
1734
|
+
return ixs;
|
|
1735
|
+
}
|
|
1736
|
+
/**
|
|
1737
|
+
* Build swap instructions with automatic SOL wrapping/unwrapping.
|
|
1738
|
+
* Wraps SOL if the input side is native, unwraps if the output side is native.
|
|
1739
|
+
*/
|
|
1740
|
+
swapSol(user, params) {
|
|
1741
|
+
const ixs = [];
|
|
1742
|
+
const inputIsX = params.isX;
|
|
1743
|
+
const inputMint = inputIsX ? this.config.mintX : this.config.mintY;
|
|
1744
|
+
const outputMint = inputIsX ? this.config.mintY : this.config.mintX;
|
|
1745
|
+
if (isNativeMint(inputMint)) {
|
|
1746
|
+
ixs.push(...wrapSolInstructions(user, params.amountIn));
|
|
1747
|
+
}
|
|
1748
|
+
if (isNativeMint(outputMint)) {
|
|
1749
|
+
ixs.push(createWsolAtaInstruction(user));
|
|
1750
|
+
}
|
|
1751
|
+
ixs.push(this.swap(user, params));
|
|
1752
|
+
if (isNativeMint(outputMint)) {
|
|
1753
|
+
ixs.push(unwrapSolInstruction(user));
|
|
1754
|
+
}
|
|
1755
|
+
return ixs;
|
|
1756
|
+
}
|
|
1640
1757
|
};
|
|
1641
1758
|
|
|
1642
1759
|
// src/orderbook.ts
|
|
@@ -2200,12 +2317,12 @@ var HadronOrderbook = class _HadronOrderbook {
|
|
|
2200
2317
|
|
|
2201
2318
|
// src/helpers/token.ts
|
|
2202
2319
|
import {
|
|
2203
|
-
getAssociatedTokenAddressSync as
|
|
2320
|
+
getAssociatedTokenAddressSync as getAssociatedTokenAddressSync6,
|
|
2204
2321
|
createAssociatedTokenAccountInstruction,
|
|
2205
|
-
TOKEN_PROGRAM_ID as
|
|
2322
|
+
TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID3
|
|
2206
2323
|
} from "@solana/spl-token";
|
|
2207
|
-
async function getOrCreateAta(connection, mint, owner, payer, tokenProgram =
|
|
2208
|
-
const address =
|
|
2324
|
+
async function getOrCreateAta(connection, mint, owner, payer, tokenProgram = TOKEN_PROGRAM_ID3, allowOwnerOffCurve = false) {
|
|
2325
|
+
const address = getAssociatedTokenAddressSync6(
|
|
2209
2326
|
mint,
|
|
2210
2327
|
owner,
|
|
2211
2328
|
allowOwnerOffCurve,
|
|
@@ -2253,6 +2370,7 @@ export {
|
|
|
2253
2370
|
MAX_SETCURVE_POINTS,
|
|
2254
2371
|
MIDPRICE_ORACLE_SEED,
|
|
2255
2372
|
MIDPRICE_ORACLE_SIZE,
|
|
2373
|
+
NATIVE_MINT,
|
|
2256
2374
|
OracleMode,
|
|
2257
2375
|
POINT_DATA_SIZE,
|
|
2258
2376
|
PoolState,
|
|
@@ -2289,6 +2407,7 @@ export {
|
|
|
2289
2407
|
buildUpdateMidpriceAndBaseSpread,
|
|
2290
2408
|
buildUpdateSpreadConfig,
|
|
2291
2409
|
buildWithdraw,
|
|
2410
|
+
createWsolAtaInstruction,
|
|
2292
2411
|
curvePrefabsSize,
|
|
2293
2412
|
decodeActiveCurves,
|
|
2294
2413
|
decodeConfig,
|
|
@@ -2308,10 +2427,13 @@ export {
|
|
|
2308
2427
|
getMidpriceOracleAddress,
|
|
2309
2428
|
getOrCreateAta,
|
|
2310
2429
|
getSpreadConfigAddress,
|
|
2430
|
+
isNativeMint,
|
|
2311
2431
|
isSlotInitialized,
|
|
2312
2432
|
pctToQ32,
|
|
2313
2433
|
spreadBpsToQ32,
|
|
2314
2434
|
spreadQ32ToBps,
|
|
2315
|
-
toQ32
|
|
2435
|
+
toQ32,
|
|
2436
|
+
unwrapSolInstruction,
|
|
2437
|
+
wrapSolInstructions
|
|
2316
2438
|
};
|
|
2317
2439
|
//# sourceMappingURL=index.mjs.map
|