@xitadel-fi/sdk 0.2.3 → 0.2.5

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.
@@ -454,7 +454,12 @@ export declare class XitadelProgram {
454
454
  verifier: PublicKey;
455
455
  accessController: PublicKey;
456
456
  config: PublicKey;
457
- }): Promise<TransactionInstruction>;
457
+ }): Promise<{
458
+ maturateIx: TransactionInstruction;
459
+ createLookupTableIx: TransactionInstruction;
460
+ extendLookupTableIx: TransactionInstruction[];
461
+ lookupTableAddress: PublicKey;
462
+ }>;
458
463
  /**
459
464
  * Stop liquidation
460
465
  * @param lttId The LTT ID
@@ -476,15 +481,12 @@ export declare class XitadelProgram {
476
481
  harvestLTT(lttId: PublicKey, manager: PublicKey, positionNftMint: PublicKey): Promise<TransactionInstruction[]>;
477
482
  getHarvestVaultPda(lttId: PublicKey): PublicKey;
478
483
  /**
479
- * Claim LP fees for an active LTT
480
- * @param signer The signer's public key
481
- * @param lttId The LTT ID
482
- * @param positionNftMint The position NFT mint
483
- * @param ammConfig The AMM config
484
- * @param cpAmmProgramId The CP AMM program ID
485
- * @returns Transaction instruction for claiming fees
484
+ * Claim LP fees from both cp_amm positions of an LTT.
485
+ * Pool B accounts default to pool A accounts when LTT is single-pool
486
+ * (positionNftMintB == default). The on-chain program skips the pool B
487
+ * CPI in that case.
486
488
  */
487
- claimFees(signer: PublicKey, lttId: PublicKey, positionNftMint: PublicKey, ammConfig: PublicKey, cpAmmProgramId: PublicKey, receiver: PublicKey): Promise<TransactionInstruction>;
489
+ claimFees(signer: PublicKey, lttId: PublicKey, positionNftMint: PublicKey, ammConfig: PublicKey, cpAmmProgramId: PublicKey, receiver: PublicKey, positionNftMintB?: PublicKey, ammConfigB?: PublicKey): Promise<TransactionInstruction>;
488
490
  /**
489
491
  * Deposit stake to flash trade from collateral vault
490
492
  * @param lttId The LTT ID
@@ -536,4 +538,13 @@ export declare class XitadelProgram {
536
538
  * @returns Transaction instruction for withdrawing stake from flash trade
537
539
  */
538
540
  withdrawStakeFlashTrade(lttId: PublicKey, authority: PublicKey, unstakeAmount: BN, lpTokenMint: PublicKey, flashTradeProgramId: PublicKey, transferAuthority: PublicKey, perpetuals: PublicKey, pool: PublicKey, flpStakeAccount: PublicKey, poolStakedLpVault: PublicKey, rewardCustody: PublicKey, eventAuthority: PublicKey): Promise<TransactionInstruction>;
541
+ /**
542
+ * Build a `version` instruction.
543
+ */
544
+ versionInstruction(): Promise<TransactionInstruction>;
545
+ /**
546
+ * Return the deployed program's git commit hash by simulating
547
+ * the `version` instruction and parsing its log output.
548
+ */
549
+ getVersion(): Promise<string>;
539
550
  }
@@ -22,16 +22,17 @@ exports.SEEDS = {
22
22
  };
23
23
  class XitadelProgram {
24
24
  constructor(provider, address) {
25
- const idl = Object.assign(xitadel_json_1.default, {});
26
- if (address) {
27
- idl.address = address;
25
+ if (process.env.NODE_ENV === 'development') {
26
+ const workspace = require('@coral-xyz/anchor').workspace;
27
+ this.program = workspace.Xitadel;
28
+ }
29
+ else {
30
+ const idl = Object.assign(xitadel_json_1.default, {});
31
+ if (address) {
32
+ idl.address = address;
33
+ }
34
+ this.program = new anchor_1.Program(idl, provider);
28
35
  }
29
- this.program = new anchor_1.Program(idl, provider);
30
- // if (process.env.NODE_ENV === 'development') {
31
- // const workspace = require('@coral-xyz/anchor').workspace;
32
- // this.program = workspace.Xitadel as Program<Xitadel>;
33
- // } else {
34
- // }
35
36
  }
36
37
  getProgramId() {
37
38
  return this.program.programId;
@@ -709,7 +710,9 @@ class XitadelProgram {
709
710
  }));
710
711
  }
711
712
  const signedReport = params.signedReport ?? Buffer.alloc(0);
712
- const signedReportBuf = Buffer.isBuffer(signedReport) ? signedReport : Buffer.from(signedReport);
713
+ const signedReportBuf = Buffer.isBuffer(signedReport)
714
+ ? signedReport
715
+ : Buffer.from(signedReport);
713
716
  const configPda = this.getConfigPda();
714
717
  instructions.push(await this.program.methods
715
718
  .activateLtt(signedReportBuf)
@@ -809,6 +812,56 @@ class XitadelProgram {
809
812
  const [positionNftAccountB] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.POSITION_NFT_ACCOUNT_SEED, positionNftMintB.toBuffer()], cpAmmProgramId);
810
813
  const collateralVaultAta = (0, spl_token_1.getAssociatedTokenAddressSync)(lttConfig.collateralTokenMint, lttConfigPda, true);
811
814
  const fundingVaultAta = (0, spl_token_1.getAssociatedTokenAddressSync)(lttConfig.fundingTokenMint, lttConfigPda, true);
815
+ const [createLookupTableIx, lookupTableAddress] = web3_js_1.AddressLookupTableProgram.createLookupTable({
816
+ authority: signer,
817
+ payer: signer,
818
+ recentSlot: await this.program.provider.connection.getSlot(),
819
+ });
820
+ const allAddresses = [
821
+ lttConfigPda,
822
+ lpAuthority,
823
+ poolAuthority,
824
+ pool,
825
+ position,
826
+ poolB,
827
+ positionB,
828
+ fundingVaultAta,
829
+ collateralVaultAta,
830
+ lttConfig.collateralTokenMint,
831
+ priceFeed,
832
+ chainLinkProgram,
833
+ verifierAccounts.verifier,
834
+ verifierAccounts.accessController,
835
+ verifierAccounts.config,
836
+ lttTokenAccount,
837
+ stableCoinTokenAccount,
838
+ lttVault,
839
+ stableVault,
840
+ lttVaultB,
841
+ stableVaultB,
842
+ lttId,
843
+ lttConfig.fundingTokenMint,
844
+ positionNftMint,
845
+ positionNftAccount,
846
+ positionNftMintB,
847
+ positionNftAccountB,
848
+ spl_token_1.TOKEN_PROGRAM_ID,
849
+ spl_token_1.TOKEN_PROGRAM_ID,
850
+ eventAuthority,
851
+ cpAmmProgramId,
852
+ ];
853
+ const uniqueAddressesStr = new Set(allAddresses.map(a => a.toBase58()));
854
+ const uniqueAddresses = Array.from(uniqueAddressesStr).map(a => new web3_js_1.PublicKey(a));
855
+ const extendLookupTableIxs = [];
856
+ const chunkSize = 15;
857
+ for (let i = 0; i < uniqueAddresses.length; i += chunkSize) {
858
+ extendLookupTableIxs.push(web3_js_1.AddressLookupTableProgram.extendLookupTable({
859
+ payer: signer,
860
+ authority: signer,
861
+ lookupTable: lookupTableAddress,
862
+ addresses: uniqueAddresses.slice(i, i + chunkSize),
863
+ }));
864
+ }
812
865
  const configPda = this.getConfigPda();
813
866
  const maturateIx = await this.program.methods
814
867
  .maturate(Buffer.from(reportBuffer))
@@ -848,7 +901,12 @@ class XitadelProgram {
848
901
  cpAmmProgram: cpAmmProgramId,
849
902
  })
850
903
  .instruction();
851
- return maturateIx;
904
+ return {
905
+ maturateIx,
906
+ createLookupTableIx,
907
+ extendLookupTableIx: extendLookupTableIxs,
908
+ lookupTableAddress,
909
+ };
852
910
  }
853
911
  /**
854
912
  * Stop liquidation
@@ -977,37 +1035,46 @@ class XitadelProgram {
977
1035
  return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('harvest_vault'), lttId.toBuffer()], this.program.programId)[0];
978
1036
  }
979
1037
  /**
980
- * Claim LP fees for an active LTT
981
- * @param signer The signer's public key
982
- * @param lttId The LTT ID
983
- * @param positionNftMint The position NFT mint
984
- * @param ammConfig The AMM config
985
- * @param cpAmmProgramId The CP AMM program ID
986
- * @returns Transaction instruction for claiming fees
1038
+ * Claim LP fees from both cp_amm positions of an LTT.
1039
+ * Pool B accounts default to pool A accounts when LTT is single-pool
1040
+ * (positionNftMintB == default). The on-chain program skips the pool B
1041
+ * CPI in that case.
987
1042
  */
988
- async claimFees(signer, lttId, positionNftMint, ammConfig, cpAmmProgramId, receiver) {
1043
+ async claimFees(signer, lttId, positionNftMint, ammConfig, cpAmmProgramId, receiver, positionNftMintB, ammConfigB) {
989
1044
  const lttConfigPda = this.getLTTConfigPda(lttId);
990
1045
  const configPda = this.getConfigPda();
991
1046
  const lttConfig = await this.getLttConfig(lttId);
992
1047
  const lpAuthority = this.getLpAuthority();
993
- // Derive pool key
1048
+ // Pool A
994
1049
  const pool = (0, utils_1.derivePoolKey)(ammConfig, lttId, lttConfig.fundingTokenMint, cpAmmProgramId);
995
- // Derive position PDA
996
1050
  const [position] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.POSITION_SEED, positionNftMint.toBuffer()], cpAmmProgramId);
997
- // Derive pool authority
998
1051
  const [poolAuthority] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.POOL_AUTHORITY_SEED], cpAmmProgramId);
999
- // Derive event authority
1000
1052
  const [eventAuthority] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('__event_authority')], cpAmmProgramId);
1001
- // Derive vault addresses
1002
1053
  const [lttVault, stableVault] = [
1003
1054
  (0, utils_1.getVaultPda)(lttId, cpAmmProgramId, pool),
1004
1055
  (0, utils_1.getVaultPda)(lttConfig.fundingTokenMint, cpAmmProgramId, pool),
1005
1056
  ];
1006
- // Get receiver's token accounts for receiving fees
1057
+ const [positionNftAccount] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('position_nft_account'), positionNftMint.toBuffer()], cpAmmProgramId);
1007
1058
  const receiverTokenAAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(lttId, receiver, true);
1008
1059
  const receiverTokenBAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(lttConfig.fundingTokenMint, receiver, true);
1009
- // Get position NFT account
1010
- const [positionNftAccount] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('position_nft_account'), positionNftMint.toBuffer()], cpAmmProgramId);
1060
+ // Pool B: prefer explicit args; fall back to on-chain position_nft_mint_b
1061
+ const onChainMintB = lttConfig.positionNftMintB;
1062
+ const hasPoolB = (positionNftMintB && !positionNftMintB.equals(web3_js_1.PublicKey.default)) ||
1063
+ (onChainMintB && !onChainMintB.equals(web3_js_1.PublicKey.default));
1064
+ let poolB = pool;
1065
+ let positionB = position;
1066
+ let lttVaultB = lttVault;
1067
+ let stableVaultB = stableVault;
1068
+ let positionNftAccountB = positionNftAccount;
1069
+ if (hasPoolB) {
1070
+ const mintB = (positionNftMintB ?? onChainMintB);
1071
+ const cfgB = ammConfigB ?? ammConfig;
1072
+ poolB = (0, utils_1.derivePoolKey)(cfgB, lttId, lttConfig.fundingTokenMint, cpAmmProgramId);
1073
+ [positionB] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.POSITION_SEED, mintB.toBuffer()], cpAmmProgramId);
1074
+ lttVaultB = (0, utils_1.getVaultPda)(lttId, cpAmmProgramId, poolB);
1075
+ stableVaultB = (0, utils_1.getVaultPda)(lttConfig.fundingTokenMint, cpAmmProgramId, poolB);
1076
+ [positionNftAccountB] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('position_nft_account'), mintB.toBuffer()], cpAmmProgramId);
1077
+ }
1011
1078
  return await this.program.methods
1012
1079
  .claimFees()
1013
1080
  .accountsPartial({
@@ -1022,9 +1089,14 @@ class XitadelProgram {
1022
1089
  stableCoinMint: lttConfig.fundingTokenMint,
1023
1090
  lttVaultAta: lttVault,
1024
1091
  stableCoinVaultAta: stableVault,
1025
- receiverTokenAAccount: receiverTokenAAccount,
1026
- receiverTokenBAccount: receiverTokenBAccount,
1092
+ receiverTokenAAccount,
1093
+ receiverTokenBAccount,
1027
1094
  positionNftAccount,
1095
+ poolB,
1096
+ positionB,
1097
+ lttVaultAtaB: lttVaultB,
1098
+ stableCoinVaultAtaB: stableVaultB,
1099
+ positionNftAccountB,
1028
1100
  eventAuthority,
1029
1101
  tokenAProgram: spl_token_1.TOKEN_PROGRAM_ID,
1030
1102
  tokenBProgram: spl_token_1.TOKEN_PROGRAM_ID,
@@ -1170,5 +1242,24 @@ class XitadelProgram {
1170
1242
  .remainingAccounts([...tokenStakeAccounts])
1171
1243
  .instruction();
1172
1244
  }
1245
+ /**
1246
+ * Build a `version` instruction.
1247
+ */
1248
+ async versionInstruction() {
1249
+ return this.program.methods.version().accounts({}).instruction();
1250
+ }
1251
+ /**
1252
+ * Return the deployed program's git commit hash by simulating
1253
+ * the `version` instruction and parsing its log output.
1254
+ */
1255
+ async getVersion() {
1256
+ const sim = await this.program.methods.version().accounts({}).simulate();
1257
+ const logs = sim.raw ?? [];
1258
+ const versionLog = logs.find((l) => l.includes('program_version:'));
1259
+ if (!versionLog) {
1260
+ throw new Error('program_version log not found in simulation output');
1261
+ }
1262
+ return versionLog.split('program_version:')[1].trim();
1263
+ }
1173
1264
  }
1174
1265
  exports.XitadelProgram = XitadelProgram;
@@ -650,6 +650,26 @@
650
650
  "name": "position_nft_account",
651
651
  "writable": true
652
652
  },
653
+ {
654
+ "name": "pool_b",
655
+ "writable": true
656
+ },
657
+ {
658
+ "name": "position_b",
659
+ "writable": true
660
+ },
661
+ {
662
+ "name": "ltt_vault_ata_b",
663
+ "writable": true
664
+ },
665
+ {
666
+ "name": "stable_coin_vault_ata_b",
667
+ "writable": true
668
+ },
669
+ {
670
+ "name": "position_nft_account_b",
671
+ "writable": true
672
+ },
653
673
  {
654
674
  "name": "event_authority",
655
675
  "writable": true
@@ -5022,6 +5042,21 @@
5022
5042
  }
5023
5043
  ]
5024
5044
  },
5045
+ {
5046
+ "name": "version",
5047
+ "discriminator": [
5048
+ 118,
5049
+ 65,
5050
+ 195,
5051
+ 198,
5052
+ 129,
5053
+ 216,
5054
+ 252,
5055
+ 192
5056
+ ],
5057
+ "accounts": [],
5058
+ "args": []
5059
+ },
5025
5060
  {
5026
5061
  "name": "withdraw_collateral",
5027
5062
  "discriminator": [
@@ -656,6 +656,26 @@ export type Xitadel = {
656
656
  "name": "positionNftAccount";
657
657
  "writable": true;
658
658
  },
659
+ {
660
+ "name": "poolB";
661
+ "writable": true;
662
+ },
663
+ {
664
+ "name": "positionB";
665
+ "writable": true;
666
+ },
667
+ {
668
+ "name": "lttVaultAtaB";
669
+ "writable": true;
670
+ },
671
+ {
672
+ "name": "stableCoinVaultAtaB";
673
+ "writable": true;
674
+ },
675
+ {
676
+ "name": "positionNftAccountB";
677
+ "writable": true;
678
+ },
659
679
  {
660
680
  "name": "eventAuthority";
661
681
  "writable": true;
@@ -5028,6 +5048,21 @@ export type Xitadel = {
5028
5048
  }
5029
5049
  ];
5030
5050
  },
5051
+ {
5052
+ "name": "version";
5053
+ "discriminator": [
5054
+ 118,
5055
+ 65,
5056
+ 195,
5057
+ 198,
5058
+ 129,
5059
+ 216,
5060
+ 252,
5061
+ 192
5062
+ ];
5063
+ "accounts": [];
5064
+ "args": [];
5065
+ },
5031
5066
  {
5032
5067
  "name": "withdrawCollateral";
5033
5068
  "discriminator": [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@xitadel-fi/sdk",
4
- "version": "0.2.3",
4
+ "version": "0.2.5",
5
5
  "description": "SDK for interacting with the Xitadel program",
6
6
  "main": "dist/sdk/src/index.js",
7
7
  "types": "dist/sdk/src/index.d.ts",