@hadron-fi/sdk 0.4.0 → 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 +30 -4
- package/dist/index.d.ts +30 -4
- package/dist/index.js +80 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -99,7 +99,9 @@ var Discriminator = {
|
|
|
99
99
|
SetPoolState: 21,
|
|
100
100
|
AllocateCurvePrefabs: 22,
|
|
101
101
|
SetQuotingAuthority: 23,
|
|
102
|
-
RotateFeeAdmin: 24
|
|
102
|
+
RotateFeeAdmin: 24,
|
|
103
|
+
InitializePoolFeeConfig: 25,
|
|
104
|
+
UpdatePoolFeeConfig: 26
|
|
103
105
|
};
|
|
104
106
|
var POINT_DATA_SIZE = 21;
|
|
105
107
|
var CURVE_UPDATE_OP_SIZE = 24;
|
|
@@ -163,6 +165,12 @@ function getCurveUpdatesAddress(seed, mintX, mintY, programId = HADRON_PROGRAM_I
|
|
|
163
165
|
function getFeeConfigAddress(programId = HADRON_PROGRAM_ID) {
|
|
164
166
|
return PublicKey3.findProgramAddressSync([FEE_CONFIG_SEED], programId);
|
|
165
167
|
}
|
|
168
|
+
function getPoolFeeConfigAddress(configPda, programId = HADRON_PROGRAM_ID) {
|
|
169
|
+
return PublicKey3.findProgramAddressSync(
|
|
170
|
+
[FEE_CONFIG_SEED, configPda.toBuffer()],
|
|
171
|
+
programId
|
|
172
|
+
);
|
|
173
|
+
}
|
|
166
174
|
function getSpreadConfigAddress(configPda, programId = HADRON_PROGRAM_ID) {
|
|
167
175
|
return PublicKey3.findProgramAddressSync(
|
|
168
176
|
[SPREAD_CONFIG_SEED, configPda.toBuffer()],
|
|
@@ -301,7 +309,9 @@ function decodeConfig(data) {
|
|
|
301
309
|
offset += 1;
|
|
302
310
|
const oracleMode = buf.readUInt8(offset);
|
|
303
311
|
offset += 1;
|
|
304
|
-
offset
|
|
312
|
+
const hasPoolFee = buf.readUInt8(offset) !== 0;
|
|
313
|
+
offset += 1;
|
|
314
|
+
offset += 2;
|
|
305
315
|
const pendingAuthority = new PublicKey4(buf.subarray(offset, offset + 32));
|
|
306
316
|
offset += 32;
|
|
307
317
|
const nominationExpiry = buf.readBigUInt64LE(offset);
|
|
@@ -320,6 +330,7 @@ function decodeConfig(data) {
|
|
|
320
330
|
spreadConfigInitialized,
|
|
321
331
|
deltaStaleness,
|
|
322
332
|
oracleMode,
|
|
333
|
+
hasPoolFee,
|
|
323
334
|
pendingAuthority,
|
|
324
335
|
nominationExpiry,
|
|
325
336
|
tokenProgramX,
|
|
@@ -541,7 +552,7 @@ function buildInitialize(payer, params, programId = HADRON_PROGRAM_ID) {
|
|
|
541
552
|
function buildAllocateCurvePrefabs(payer, params, programId = HADRON_PROGRAM_ID) {
|
|
542
553
|
const maxPrefabSlots = params.maxPrefabSlots ?? DEFAULT_MAX_PREFAB_SLOTS;
|
|
543
554
|
const maxCurvePoints = params.maxCurvePoints ?? DEFAULT_MAX_CURVE_POINTS;
|
|
544
|
-
const data = Buffer.alloc(1 + 8 + 32 + 32 + 1 + 1);
|
|
555
|
+
const data = Buffer.alloc(1 + 8 + 32 + 32 + 1 + 1 + 32);
|
|
545
556
|
let offset = 0;
|
|
546
557
|
data.writeUInt8(Discriminator.AllocateCurvePrefabs, offset);
|
|
547
558
|
offset += 1;
|
|
@@ -554,6 +565,8 @@ function buildAllocateCurvePrefabs(payer, params, programId = HADRON_PROGRAM_ID)
|
|
|
554
565
|
data.writeUInt8(maxPrefabSlots, offset);
|
|
555
566
|
offset += 1;
|
|
556
567
|
data.writeUInt8(maxCurvePoints, offset);
|
|
568
|
+
offset += 1;
|
|
569
|
+
params.authority.toBuffer().copy(data, offset);
|
|
557
570
|
const [curvePrefabsPda] = PublicKey5.findProgramAddressSync(
|
|
558
571
|
[
|
|
559
572
|
Buffer.from("hadron-curve-prefabs"),
|
|
@@ -653,7 +666,7 @@ import {
|
|
|
653
666
|
TransactionInstruction as TransactionInstruction5
|
|
654
667
|
} from "@solana/web3.js";
|
|
655
668
|
import { getAssociatedTokenAddressSync as getAssociatedTokenAddressSync5 } from "@solana/spl-token";
|
|
656
|
-
function buildSwapExactIn(user, poolAddresses, mintX, mintY, tokenProgramX, tokenProgramY, params, programId = HADRON_PROGRAM_ID, spreadConfigInitialized = false) {
|
|
669
|
+
function buildSwapExactIn(user, poolAddresses, mintX, mintY, tokenProgramX, tokenProgramY, params, programId = HADRON_PROGRAM_ID, spreadConfigInitialized = false, feeConfigOverride) {
|
|
657
670
|
const data = Buffer.alloc(1 + 1 + 8 + 8 + 8);
|
|
658
671
|
let offset = 0;
|
|
659
672
|
data.writeUInt8(Discriminator.SwapExactIn, offset);
|
|
@@ -669,7 +682,7 @@ function buildSwapExactIn(user, poolAddresses, mintX, mintY, tokenProgramX, toke
|
|
|
669
682
|
const userX = getAssociatedTokenAddressSync5(mintX, user, false, tokenProgramX);
|
|
670
683
|
const userY = getAssociatedTokenAddressSync5(mintY, user, false, tokenProgramY);
|
|
671
684
|
const [userSource, vaultSource, vaultDest, userDest] = params.isX ? [userX, poolAddresses.vaultX, poolAddresses.vaultY, userY] : [userY, poolAddresses.vaultY, poolAddresses.vaultX, userX];
|
|
672
|
-
const
|
|
685
|
+
const feeConfigPda = feeConfigOverride ?? getFeeConfigAddress(programId)[0];
|
|
673
686
|
const inputMint = params.isX ? mintX : mintY;
|
|
674
687
|
const inputMintProgram = params.isX ? tokenProgramX : tokenProgramY;
|
|
675
688
|
const feeRecipientAta = getAssociatedTokenAddressSync5(
|
|
@@ -1137,6 +1150,52 @@ function buildRotateFeeAdmin(feeAdmin, params, programId = HADRON_PROGRAM_ID) {
|
|
|
1137
1150
|
data
|
|
1138
1151
|
});
|
|
1139
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
|
+
}
|
|
1140
1199
|
|
|
1141
1200
|
// src/instructions/spreadConfig.ts
|
|
1142
1201
|
import {
|
|
@@ -1216,7 +1275,7 @@ function buildUpdateDeltaStaleness(authority, configPda, params, programId = HAD
|
|
|
1216
1275
|
data
|
|
1217
1276
|
});
|
|
1218
1277
|
}
|
|
1219
|
-
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) {
|
|
1220
1279
|
const data = Buffer.alloc(1);
|
|
1221
1280
|
data.writeUInt8(Discriminator.ClosePool, 0);
|
|
1222
1281
|
const keys = [
|
|
@@ -1239,6 +1298,12 @@ function buildClosePool(authority, configPda, midpriceOraclePda, curveMetaPda, c
|
|
|
1239
1298
|
isWritable: true
|
|
1240
1299
|
});
|
|
1241
1300
|
}
|
|
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
|
+
}
|
|
1242
1307
|
return new TransactionInstruction13({ programId, keys, data });
|
|
1243
1308
|
}
|
|
1244
1309
|
|
|
@@ -1340,7 +1405,8 @@ var Hadron = class _Hadron {
|
|
|
1340
1405
|
mintX: params.mintX,
|
|
1341
1406
|
mintY: params.mintY,
|
|
1342
1407
|
maxPrefabSlots,
|
|
1343
|
-
maxCurvePoints
|
|
1408
|
+
maxCurvePoints,
|
|
1409
|
+
authority: params.authority
|
|
1344
1410
|
};
|
|
1345
1411
|
const instructions = [];
|
|
1346
1412
|
const size = curvePrefabsSize(maxPrefabSlots, maxCurvePoints);
|
|
@@ -1683,7 +1749,7 @@ var Hadron = class _Hadron {
|
|
|
1683
1749
|
return decoded.triggers;
|
|
1684
1750
|
}
|
|
1685
1751
|
/** Build close pool instruction. */
|
|
1686
|
-
closePool(authority) {
|
|
1752
|
+
closePool(authority, authorityAtaX, authorityAtaY) {
|
|
1687
1753
|
return buildClosePool(
|
|
1688
1754
|
authority,
|
|
1689
1755
|
this.poolAddress,
|
|
@@ -1696,6 +1762,8 @@ var Hadron = class _Hadron {
|
|
|
1696
1762
|
this.config.tokenProgramX,
|
|
1697
1763
|
this.config.tokenProgramY,
|
|
1698
1764
|
this.config.spreadConfigInitialized,
|
|
1765
|
+
authorityAtaX,
|
|
1766
|
+
authorityAtaY,
|
|
1699
1767
|
this.programId
|
|
1700
1768
|
);
|
|
1701
1769
|
}
|
|
@@ -2385,6 +2453,7 @@ export {
|
|
|
2385
2453
|
buildDeposit,
|
|
2386
2454
|
buildInitialize,
|
|
2387
2455
|
buildInitializeFeeConfig,
|
|
2456
|
+
buildInitializePoolFeeConfig,
|
|
2388
2457
|
buildInitializeSpreadConfig,
|
|
2389
2458
|
buildNominateAuthority,
|
|
2390
2459
|
buildRotateFeeAdmin,
|
|
@@ -2405,6 +2474,7 @@ export {
|
|
|
2405
2474
|
buildUpdateFeeConfig,
|
|
2406
2475
|
buildUpdateMidprice,
|
|
2407
2476
|
buildUpdateMidpriceAndBaseSpread,
|
|
2477
|
+
buildUpdatePoolFeeConfig,
|
|
2408
2478
|
buildUpdateSpreadConfig,
|
|
2409
2479
|
buildWithdraw,
|
|
2410
2480
|
createWsolAtaInstruction,
|
|
@@ -2426,6 +2496,7 @@ export {
|
|
|
2426
2496
|
getFeeConfigAddress,
|
|
2427
2497
|
getMidpriceOracleAddress,
|
|
2428
2498
|
getOrCreateAta,
|
|
2499
|
+
getPoolFeeConfigAddress,
|
|
2429
2500
|
getSpreadConfigAddress,
|
|
2430
2501
|
isNativeMint,
|
|
2431
2502
|
isSlotInitialized,
|