@0dotxyz/p0-ts-sdk 2.3.0-alpha.2 → 2.3.0-alpha.4

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/vendor.cjs CHANGED
@@ -32348,11 +32348,13 @@ function selectBestRoute(quotes, swapMode) {
32348
32348
  }
32349
32349
  function buildSwapQuoteResult(route, swapMode) {
32350
32350
  const slippageBps = route.slippageBps;
32351
+ const outAmount = Number(route.outAmount);
32352
+ const inAmount = Number(route.inAmount);
32351
32353
  let otherAmountThreshold;
32352
32354
  if (swapMode === "ExactIn") {
32353
- otherAmountThreshold = String(Math.floor(route.outAmount * (1 - slippageBps / 1e4)));
32355
+ otherAmountThreshold = String(Math.floor(outAmount * (1 - slippageBps / 1e4)));
32354
32356
  } else {
32355
- otherAmountThreshold = String(Math.ceil(route.inAmount * (1 + slippageBps / 1e4)));
32357
+ otherAmountThreshold = String(Math.ceil(inAmount * (1 + slippageBps / 1e4)));
32356
32358
  }
32357
32359
  return {
32358
32360
  inAmount: String(route.inAmount),
@@ -32516,13 +32518,31 @@ function deserializeTitanWireInstruction(ix) {
32516
32518
  });
32517
32519
  }
32518
32520
  var EXPONENT_CORE_PROGRAM_ID = new web3_js.PublicKey(
32519
- "XP1BRLn8eCYSygrd8er5P4GKdzqKbC3DLoSsS5UYVZy"
32521
+ "ExponentnaRg3CQbW6dqQNZKXp7gtZ9DGMp1cwC4HAS7"
32520
32522
  );
32521
- var EXPONENT_WRAPPER_PROGRAM_ID = new web3_js.PublicKey(
32523
+ var EXPONENT_CLMM_PROGRAM_ID = new web3_js.PublicKey(
32522
32524
  "XPC1MM4dYACDfykNuXYZ5una2DsMDWL24CrYubCvarC"
32523
32525
  );
32524
- var EXPONENT_LOCALNET_PROGRAM_ID = new web3_js.PublicKey(
32525
- "ExponentnaRg3CQbW6dqQNZKXp7gtZ9DGMp1cwC4HAS7"
32526
+ var EXPONENT_ORDERBOOK_PROGRAM_ID = new web3_js.PublicKey(
32527
+ "XPBookgQTN2p8Yw1C2La35XkPMmZTCEYH77AdReVvK1"
32528
+ );
32529
+ var EXPONENT_VAULTS_PROGRAM_ID = new web3_js.PublicKey(
32530
+ "sVau1tXvayVWfotzm9Ahcv2qfnnfRWttt78BCnNC6dD"
32531
+ );
32532
+ var EXPONENT_GENERIC_SY_PROGRAM_ID = new web3_js.PublicKey(
32533
+ "XP1BRLn8eCYSygrd8er5P4GKdzqKbC3DLoSsS5UYVZy"
32534
+ );
32535
+ var EXPONENT_MARGINFI_SY_PROGRAM_ID = new web3_js.PublicKey(
32536
+ "XPMfipyhcbq3DBvgvxkbZY7GekwmGNJLMD3wdiCkBc7"
32537
+ );
32538
+ var EXPONENT_KAMINO_SY_PROGRAM_ID = new web3_js.PublicKey(
32539
+ "XPK1ndTK1xrgRg99ifvdPP1exrx8D1mRXTuxBkkroCx"
32540
+ );
32541
+ var EXPONENT_JITO_RESTAKING_SY_PROGRAM_ID = new web3_js.PublicKey(
32542
+ "XPJitopeUEhMZVF72CvswnwrS2U2akQvk5s26aEfWv2"
32543
+ );
32544
+ var EXPONENT_PERENA_SY_PROGRAM_ID = new web3_js.PublicKey(
32545
+ "XPerenaJPyvnjseLCn7rgzxFEum6zX1k89C13SPTyGZ"
32526
32546
  );
32527
32547
  var EXPONENT_EVENT_AUTHORITY_SEED = "__event_authority";
32528
32548
 
@@ -39746,6 +39766,7 @@ function decodeExponentVault(data) {
39746
39766
  const d = EXPONENT_ACCOUNTS_CODER.decode("Vault", data);
39747
39767
  const get = (snake, camel) => d[snake] ?? d[camel];
39748
39768
  const u646 = (v) => BigInt(BN2__default.default.isBN(v) ? v.toString() : String(v ?? 0));
39769
+ const cpi = get("cpi_accounts", "cpiAccounts") ?? {};
39749
39770
  return {
39750
39771
  authority: pk(get("authority", "authority")),
39751
39772
  syProgram: pk(get("sy_program", "syProgram")),
@@ -39755,8 +39776,16 @@ function decodeExponentVault(data) {
39755
39776
  escrowSy: pk(get("escrow_sy", "escrowSy")),
39756
39777
  yieldPosition: pk(get("yield_position", "yieldPosition")),
39757
39778
  addressLookupTable: pk(get("address_lookup_table", "addressLookupTable")),
39779
+ cpiAccounts: {
39780
+ getSyState: decodeCpiContexts(cpi.get_sy_state ?? cpi.getSyState),
39781
+ depositSy: decodeCpiContexts(cpi.deposit_sy ?? cpi.depositSy),
39782
+ withdrawSy: decodeCpiContexts(cpi.withdraw_sy ?? cpi.withdrawSy)
39783
+ },
39758
39784
  syForPt: u646(get("sy_for_pt", "syForPt")),
39759
39785
  ptSupply: u646(get("pt_supply", "ptSupply")),
39786
+ lastSeenSyExchangeRate: exponentNumberToBigNumber(
39787
+ get("last_seen_sy_exchange_rate", "lastSeenSyExchangeRate")
39788
+ ),
39760
39789
  finalSyExchangeRate: exponentNumberToBigNumber(
39761
39790
  get("final_sy_exchange_rate", "finalSyExchangeRate")
39762
39791
  ),
@@ -39767,6 +39796,44 @@ function decodeExponentMarketVault(data) {
39767
39796
  const d = EXPONENT_ACCOUNTS_CODER.decode("MarketTwo", data);
39768
39797
  return pk(d.vault);
39769
39798
  }
39799
+ function decodeCpiContexts(raw) {
39800
+ if (!Array.isArray(raw)) return [];
39801
+ return raw.map((c) => {
39802
+ const o = c ?? {};
39803
+ return {
39804
+ altIndex: Number(o.alt_index ?? o.altIndex ?? 0),
39805
+ isSigner: Boolean(o.is_signer ?? o.isSigner ?? false),
39806
+ isWritable: Boolean(o.is_writable ?? o.isWritable ?? false)
39807
+ };
39808
+ });
39809
+ }
39810
+ function decodeExponentMarketTwo(data) {
39811
+ const d = EXPONENT_ACCOUNTS_CODER.decode("MarketTwo", data);
39812
+ const get = (snake, camel) => d[snake] ?? d[camel];
39813
+ const cpi = get("cpi_accounts", "cpiAccounts") ?? {};
39814
+ return {
39815
+ selfAddress: pk(get("self_address", "selfAddress")),
39816
+ mintPt: pk(get("mint_pt", "mintPt")),
39817
+ mintSy: pk(get("mint_sy", "mintSy")),
39818
+ vault: pk(get("vault", "vault")),
39819
+ tokenPtEscrow: pk(get("token_pt_escrow", "tokenPtEscrow")),
39820
+ tokenSyEscrow: pk(get("token_sy_escrow", "tokenSyEscrow")),
39821
+ tokenFeeTreasurySy: pk(get("token_fee_treasury_sy", "tokenFeeTreasurySy")),
39822
+ addressLookupTable: pk(get("address_lookup_table", "addressLookupTable")),
39823
+ syProgram: pk(get("sy_program", "syProgram")),
39824
+ statusFlags: Number(get("status_flags", "statusFlags") ?? 0),
39825
+ cpiAccounts: {
39826
+ getSyState: decodeCpiContexts(cpi.get_sy_state ?? cpi.getSyState),
39827
+ depositSy: decodeCpiContexts(cpi.deposit_sy ?? cpi.depositSy),
39828
+ withdrawSy: decodeCpiContexts(cpi.withdraw_sy ?? cpi.withdrawSy)
39829
+ }
39830
+ };
39831
+ }
39832
+ async function fetchExponentMarketTwo(connection, market) {
39833
+ const info = await connection.getAccountInfo(market);
39834
+ if (!info) throw new Error(`Exponent market account not found: ${market.toBase58()}`);
39835
+ return decodeExponentMarketTwo(info.data);
39836
+ }
39770
39837
  async function fetchExponentVault(connection, vault) {
39771
39838
  const info = await connection.getAccountInfo(vault);
39772
39839
  if (!info) throw new Error(`Exponent vault account not found: ${vault.toBase58()}`);
@@ -39789,6 +39856,180 @@ function deriveExponentEventAuthority() {
39789
39856
  EXPONENT_CORE_PROGRAM_ID
39790
39857
  )[0];
39791
39858
  }
39859
+ var MERGE_DISCRIMINATOR = Buffer.from([5]);
39860
+ function makeExponentMergeIx(accounts, amountNative) {
39861
+ const tokenProgram = accounts.tokenProgram ?? TOKEN_PROGRAM_ID;
39862
+ const eventAuthority = deriveExponentEventAuthority();
39863
+ const data = Buffer.alloc(MERGE_DISCRIMINATOR.length + 8);
39864
+ MERGE_DISCRIMINATOR.copy(data, 0);
39865
+ data.writeBigUInt64LE(amountNative, MERGE_DISCRIMINATOR.length);
39866
+ const keys = [
39867
+ { pubkey: accounts.owner, isSigner: true, isWritable: true },
39868
+ { pubkey: accounts.authority, isSigner: false, isWritable: true },
39869
+ { pubkey: accounts.vault, isSigner: false, isWritable: true },
39870
+ { pubkey: accounts.sySrcDstAta, isSigner: false, isWritable: true },
39871
+ { pubkey: accounts.escrowSy, isSigner: false, isWritable: true },
39872
+ { pubkey: accounts.ytSrcAta, isSigner: false, isWritable: true },
39873
+ { pubkey: accounts.ptSrcAta, isSigner: false, isWritable: true },
39874
+ { pubkey: accounts.mintYt, isSigner: false, isWritable: true },
39875
+ { pubkey: accounts.mintPt, isSigner: false, isWritable: true },
39876
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
39877
+ { pubkey: accounts.syProgram, isSigner: false, isWritable: false },
39878
+ { pubkey: accounts.addressLookupTable, isSigner: false, isWritable: false },
39879
+ { pubkey: accounts.yieldPosition, isSigner: false, isWritable: true },
39880
+ { pubkey: eventAuthority, isSigner: false, isWritable: false },
39881
+ { pubkey: EXPONENT_CORE_PROGRAM_ID, isSigner: false, isWritable: false },
39882
+ // SY-program CPI accounts (getSyState ++ withdrawSy), ALT-resolved (post-maturity merge
39883
+ // still CPIs into the SY program to move SY out of escrow).
39884
+ ...accounts.remainingAccounts ?? []
39885
+ ];
39886
+ return new web3_js.TransactionInstruction({
39887
+ keys,
39888
+ programId: EXPONENT_CORE_PROGRAM_ID,
39889
+ data
39890
+ });
39891
+ }
39892
+ var TRADE_PT_DISCRIMINATOR = Buffer.from([17]);
39893
+ function exponentBuyPtArgs({
39894
+ ptOutNative,
39895
+ maxSyInNative
39896
+ }) {
39897
+ return { netTraderPt: ptOutNative, syConstraint: -maxSyInNative };
39898
+ }
39899
+ function makeExponentTradePtIx(accounts, args) {
39900
+ const tokenProgram = accounts.tokenProgram ?? TOKEN_PROGRAM_ID;
39901
+ const eventAuthority = deriveExponentEventAuthority();
39902
+ const data = Buffer.alloc(TRADE_PT_DISCRIMINATOR.length + 16);
39903
+ TRADE_PT_DISCRIMINATOR.copy(data, 0);
39904
+ data.writeBigInt64LE(args.netTraderPt, TRADE_PT_DISCRIMINATOR.length);
39905
+ data.writeBigInt64LE(args.syConstraint, TRADE_PT_DISCRIMINATOR.length + 8);
39906
+ const keys = [
39907
+ { pubkey: accounts.trader, isSigner: true, isWritable: true },
39908
+ { pubkey: accounts.market, isSigner: false, isWritable: true },
39909
+ { pubkey: accounts.tokenSyTrader, isSigner: false, isWritable: true },
39910
+ { pubkey: accounts.tokenPtTrader, isSigner: false, isWritable: true },
39911
+ { pubkey: accounts.tokenSyEscrow, isSigner: false, isWritable: true },
39912
+ { pubkey: accounts.tokenPtEscrow, isSigner: false, isWritable: true },
39913
+ { pubkey: accounts.addressLookupTable, isSigner: false, isWritable: false },
39914
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
39915
+ { pubkey: accounts.syProgram, isSigner: false, isWritable: false },
39916
+ { pubkey: accounts.tokenFeeTreasurySy, isSigner: false, isWritable: true },
39917
+ { pubkey: eventAuthority, isSigner: false, isWritable: false },
39918
+ { pubkey: EXPONENT_CORE_PROGRAM_ID, isSigner: false, isWritable: false },
39919
+ // SY-program CPI accounts (getSyState ++ depositSy ++ withdrawSy), ALT-resolved.
39920
+ ...accounts.remainingAccounts
39921
+ ];
39922
+ return new web3_js.TransactionInstruction({
39923
+ keys,
39924
+ programId: EXPONENT_CORE_PROGRAM_ID,
39925
+ data
39926
+ });
39927
+ }
39928
+ var STRIP_DISCRIMINATOR = Buffer.from([4]);
39929
+ function makeExponentStripIx(accounts, amountNative) {
39930
+ const tokenProgram = accounts.tokenProgram ?? TOKEN_PROGRAM_ID;
39931
+ const eventAuthority = deriveExponentEventAuthority();
39932
+ const data = Buffer.alloc(STRIP_DISCRIMINATOR.length + 8);
39933
+ STRIP_DISCRIMINATOR.copy(data, 0);
39934
+ data.writeBigUInt64LE(amountNative, STRIP_DISCRIMINATOR.length);
39935
+ const keys = [
39936
+ { pubkey: accounts.depositor, isSigner: true, isWritable: true },
39937
+ { pubkey: accounts.authority, isSigner: false, isWritable: true },
39938
+ { pubkey: accounts.vault, isSigner: false, isWritable: true },
39939
+ { pubkey: accounts.sySrc, isSigner: false, isWritable: true },
39940
+ { pubkey: accounts.escrowSy, isSigner: false, isWritable: true },
39941
+ { pubkey: accounts.ytDst, isSigner: false, isWritable: true },
39942
+ { pubkey: accounts.ptDst, isSigner: false, isWritable: true },
39943
+ { pubkey: accounts.mintYt, isSigner: false, isWritable: true },
39944
+ { pubkey: accounts.mintPt, isSigner: false, isWritable: true },
39945
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
39946
+ { pubkey: accounts.addressLookupTable, isSigner: false, isWritable: false },
39947
+ { pubkey: accounts.syProgram, isSigner: false, isWritable: false },
39948
+ { pubkey: accounts.yieldPosition, isSigner: false, isWritable: true },
39949
+ { pubkey: eventAuthority, isSigner: false, isWritable: false },
39950
+ { pubkey: EXPONENT_CORE_PROGRAM_ID, isSigner: false, isWritable: false },
39951
+ // SY-program CPI accounts (depositSy), ALT-resolved.
39952
+ ...accounts.remainingAccounts ?? []
39953
+ ];
39954
+ return new web3_js.TransactionInstruction({ keys, programId: EXPONENT_CORE_PROGRAM_ID, data });
39955
+ }
39956
+ var WRAPPER_MERGE_DISCRIMINATOR = Buffer.from([39]);
39957
+ function makeExponentWrapperMergeIx(accounts, args) {
39958
+ const tokenProgram = accounts.tokenProgram ?? TOKEN_PROGRAM_ID;
39959
+ const eventAuthority = deriveExponentEventAuthority();
39960
+ const data = Buffer.alloc(WRAPPER_MERGE_DISCRIMINATOR.length + 9);
39961
+ WRAPPER_MERGE_DISCRIMINATOR.copy(data, 0);
39962
+ data.writeBigUInt64LE(args.amountPyNative, WRAPPER_MERGE_DISCRIMINATOR.length);
39963
+ data.writeUInt8(args.redeemSyAccountsUntil, WRAPPER_MERGE_DISCRIMINATOR.length + 8);
39964
+ const keys = [
39965
+ { pubkey: accounts.owner, isSigner: true, isWritable: true },
39966
+ { pubkey: accounts.syAta, isSigner: false, isWritable: true },
39967
+ { pubkey: accounts.vault, isSigner: false, isWritable: true },
39968
+ { pubkey: accounts.escrowSy, isSigner: false, isWritable: true },
39969
+ { pubkey: accounts.ytAta, isSigner: false, isWritable: true },
39970
+ { pubkey: accounts.ptAta, isSigner: false, isWritable: true },
39971
+ { pubkey: accounts.mintYt, isSigner: false, isWritable: true },
39972
+ { pubkey: accounts.mintPt, isSigner: false, isWritable: true },
39973
+ { pubkey: accounts.authority, isSigner: false, isWritable: true },
39974
+ { pubkey: accounts.addressLookupTable, isSigner: false, isWritable: false },
39975
+ { pubkey: tokenProgram, isSigner: false, isWritable: false },
39976
+ { pubkey: accounts.yieldPosition, isSigner: false, isWritable: true },
39977
+ { pubkey: accounts.syProgram, isSigner: false, isWritable: false },
39978
+ { pubkey: web3_js.SystemProgram.programId, isSigner: false, isWritable: false },
39979
+ { pubkey: eventAuthority, isSigner: false, isWritable: false },
39980
+ { pubkey: EXPONENT_CORE_PROGRAM_ID, isSigner: false, isWritable: false },
39981
+ // [...redeem (flavor SY-redeem accounts), ...cpi (withdraw_sy ++ get_sy_state)]
39982
+ ...accounts.remainingAccounts
39983
+ ];
39984
+ return new web3_js.TransactionInstruction({ keys, programId: EXPONENT_CORE_PROGRAM_ID, data });
39985
+ }
39986
+ var SPL_STAKE_POOL_UPDATE_BALANCE_TAG = Buffer.from([7]);
39987
+ function makeSplStakePoolUpdateBalanceIx(accounts) {
39988
+ const tokenProgram = accounts.tokenProgram ?? TOKEN_PROGRAM_ID;
39989
+ const keys = [
39990
+ { pubkey: accounts.stakePool, isSigner: false, isWritable: true },
39991
+ { pubkey: accounts.withdrawAuthority, isSigner: false, isWritable: false },
39992
+ { pubkey: accounts.validatorList, isSigner: false, isWritable: true },
39993
+ { pubkey: accounts.reserveStake, isSigner: false, isWritable: false },
39994
+ { pubkey: accounts.managerFeeAccount, isSigner: false, isWritable: true },
39995
+ { pubkey: accounts.poolMint, isSigner: false, isWritable: true },
39996
+ { pubkey: tokenProgram, isSigner: false, isWritable: false }
39997
+ ];
39998
+ return new web3_js.TransactionInstruction({
39999
+ keys,
40000
+ programId: accounts.stakePoolProgram,
40001
+ data: Buffer.from(SPL_STAKE_POOL_UPDATE_BALANCE_TAG)
40002
+ });
40003
+ }
40004
+
40005
+ // src/vendor/exponent/utils/resolve.utils.ts
40006
+ function resolveCpiMetas(contexts, altAddresses, altKey) {
40007
+ return contexts.map((ctx) => {
40008
+ const pubkey = altAddresses[ctx.altIndex];
40009
+ if (!pubkey) {
40010
+ throw new Error(
40011
+ `Exponent CPI account alt_index ${ctx.altIndex} out of range (ALT ${altKey.toBase58()} has ${altAddresses.length} entries)`
40012
+ );
40013
+ }
40014
+ return { pubkey, isSigner: false, isWritable: ctx.isWritable };
40015
+ });
40016
+ }
40017
+ function uniqueRemainingAccounts(metas) {
40018
+ const seen = /* @__PURE__ */ new Map();
40019
+ for (const m of metas) {
40020
+ const key = m.pubkey.toBase58();
40021
+ const prev = seen.get(key);
40022
+ if (prev) prev.isWritable = prev.isWritable || m.isWritable;
40023
+ else seen.set(key, { ...m });
40024
+ }
40025
+ return [...seen.values()];
40026
+ }
40027
+ var STAKE_POOL_OFFSETS = {
40028
+ validatorList: 98,
40029
+ reserveStake: 130,
40030
+ poolMint: 162,
40031
+ managerFeeAccount: 194
40032
+ };
39792
40033
  async function resolveExponentMergeContext(params) {
39793
40034
  const { connection, owner } = params;
39794
40035
  const ptYtTokenProgram = params.ptYtTokenProgram ?? TOKEN_PROGRAM_ID;
@@ -39808,6 +40049,17 @@ async function resolveExponentMergeContext(params) {
39808
40049
  const ptSrcAta = getAssociatedTokenAddressSync(vault.mintPt, owner, true, ptYtTokenProgram);
39809
40050
  const ytSrcAta = getAssociatedTokenAddressSync(vault.mintYt, owner, true, ptYtTokenProgram);
39810
40051
  const sySrcDstAta = getAssociatedTokenAddressSync(vault.mintSy, owner, true, syTokenProgram);
40052
+ const altResult = await connection.getAddressLookupTable(vault.addressLookupTable);
40053
+ const alt = altResult.value;
40054
+ if (!alt) {
40055
+ throw new Error(
40056
+ `Exponent vault address lookup table not found: ${vault.addressLookupTable.toBase58()}`
40057
+ );
40058
+ }
40059
+ const remainingAccounts = [
40060
+ ...resolveCpiMetas(vault.cpiAccounts.getSyState, alt.state.addresses, vault.addressLookupTable),
40061
+ ...resolveCpiMetas(vault.cpiAccounts.withdrawSy, alt.state.addresses, vault.addressLookupTable)
40062
+ ];
39811
40063
  const mergeAccounts = {
39812
40064
  owner,
39813
40065
  authority: vault.authority,
@@ -39821,13 +40073,15 @@ async function resolveExponentMergeContext(params) {
39821
40073
  syProgram: vault.syProgram,
39822
40074
  addressLookupTable: vault.addressLookupTable,
39823
40075
  yieldPosition: vault.yieldPosition,
39824
- tokenProgram: ptYtTokenProgram
40076
+ tokenProgram: ptYtTokenProgram,
40077
+ remainingAccounts
39825
40078
  };
39826
40079
  const decimals = await getMintDecimals(connection, vault.mintSy);
39827
40080
  return {
39828
40081
  vaultAddress,
39829
40082
  vault,
39830
40083
  mergeAccounts,
40084
+ addressLookupTable: alt,
39831
40085
  underlying: { mint: vault.mintSy, decimals, tokenProgram: syTokenProgram },
39832
40086
  computeRedeemedAmountNative(ptAmountNative) {
39833
40087
  if (vault.ptSupply === 0n) return 0n;
@@ -39836,36 +40090,232 @@ async function resolveExponentMergeContext(params) {
39836
40090
  }
39837
40091
  };
39838
40092
  }
39839
- var MERGE_DISCRIMINATOR = Buffer.from([5]);
39840
- function makeExponentMergeIx(accounts, amountNative) {
39841
- const tokenProgram = accounts.tokenProgram ?? TOKEN_PROGRAM_ID;
39842
- const eventAuthority = deriveExponentEventAuthority();
39843
- const data = Buffer.alloc(MERGE_DISCRIMINATOR.length + 8);
39844
- MERGE_DISCRIMINATOR.copy(data, 0);
39845
- data.writeBigUInt64LE(amountNative, MERGE_DISCRIMINATOR.length);
39846
- const keys = [
39847
- { pubkey: accounts.owner, isSigner: true, isWritable: true },
39848
- { pubkey: accounts.authority, isSigner: false, isWritable: true },
39849
- { pubkey: accounts.vault, isSigner: false, isWritable: true },
39850
- { pubkey: accounts.sySrcDstAta, isSigner: false, isWritable: true },
39851
- { pubkey: accounts.escrowSy, isSigner: false, isWritable: true },
39852
- { pubkey: accounts.ytSrcAta, isSigner: false, isWritable: true },
39853
- { pubkey: accounts.ptSrcAta, isSigner: false, isWritable: true },
39854
- { pubkey: accounts.mintYt, isSigner: false, isWritable: true },
39855
- { pubkey: accounts.mintPt, isSigner: false, isWritable: true },
39856
- { pubkey: tokenProgram, isSigner: false, isWritable: false },
39857
- { pubkey: accounts.syProgram, isSigner: false, isWritable: false },
39858
- { pubkey: accounts.addressLookupTable, isSigner: false, isWritable: false },
39859
- { pubkey: accounts.yieldPosition, isSigner: false, isWritable: true },
39860
- { pubkey: eventAuthority, isSigner: false, isWritable: false },
39861
- { pubkey: EXPONENT_CORE_PROGRAM_ID, isSigner: false, isWritable: false }
40093
+ async function resolveExponentTradePtContext(params) {
40094
+ const { connection, owner } = params;
40095
+ const ptTokenProgram = params.ptTokenProgram ?? TOKEN_PROGRAM_ID;
40096
+ const syTokenProgram = params.syTokenProgram ?? TOKEN_PROGRAM_ID;
40097
+ const market = await fetchExponentMarketTwo(connection, params.market);
40098
+ const altResult = await connection.getAddressLookupTable(market.addressLookupTable);
40099
+ const alt = altResult.value;
40100
+ if (!alt) {
40101
+ throw new Error(
40102
+ `Exponent market address lookup table not found: ${market.addressLookupTable.toBase58()}`
40103
+ );
40104
+ }
40105
+ const altAddresses = alt.state.addresses;
40106
+ const altKey = market.addressLookupTable;
40107
+ const remainingAccounts = [
40108
+ ...resolveCpiMetas(market.cpiAccounts.getSyState, altAddresses, altKey),
40109
+ ...resolveCpiMetas(market.cpiAccounts.depositSy, altAddresses, altKey),
40110
+ ...resolveCpiMetas(market.cpiAccounts.withdrawSy, altAddresses, altKey)
39862
40111
  ];
39863
- return new web3_js.TransactionInstruction({
39864
- keys,
39865
- programId: EXPONENT_CORE_PROGRAM_ID,
39866
- data
40112
+ const tokenSyTrader = getAssociatedTokenAddressSync(market.mintSy, owner, true, syTokenProgram);
40113
+ const tokenPtTrader = getAssociatedTokenAddressSync(market.mintPt, owner, true, ptTokenProgram);
40114
+ const tradePtAccounts = {
40115
+ trader: owner,
40116
+ market: market.selfAddress,
40117
+ tokenSyTrader,
40118
+ tokenPtTrader,
40119
+ tokenSyEscrow: market.tokenSyEscrow,
40120
+ tokenPtEscrow: market.tokenPtEscrow,
40121
+ addressLookupTable: market.addressLookupTable,
40122
+ syProgram: market.syProgram,
40123
+ tokenFeeTreasurySy: market.tokenFeeTreasurySy,
40124
+ tokenProgram: ptTokenProgram,
40125
+ remainingAccounts
40126
+ };
40127
+ const [syDecimals, ptDecimals] = await Promise.all([
40128
+ getMintDecimals(connection, market.mintSy),
40129
+ getMintDecimals(connection, market.mintPt)
40130
+ ]);
40131
+ return {
40132
+ marketAddress: market.selfAddress,
40133
+ market,
40134
+ tradePtAccounts,
40135
+ addressLookupTable: alt,
40136
+ sy: { mint: market.mintSy, decimals: syDecimals, tokenProgram: syTokenProgram },
40137
+ pt: { mint: market.mintPt, decimals: ptDecimals, tokenProgram: ptTokenProgram }
40138
+ };
40139
+ }
40140
+ async function resolveExponentStripContext(params) {
40141
+ const { connection, owner } = params;
40142
+ const ptYtTokenProgram = params.ptYtTokenProgram ?? TOKEN_PROGRAM_ID;
40143
+ const syTokenProgram = params.syTokenProgram ?? TOKEN_PROGRAM_ID;
40144
+ let vaultAddress;
40145
+ let vault;
40146
+ if (params.vault) {
40147
+ vaultAddress = params.vault;
40148
+ vault = await fetchExponentVault(connection, vaultAddress);
40149
+ } else if (params.market) {
40150
+ const res = await fetchExponentVaultFromMarket(connection, params.market);
40151
+ vaultAddress = res.vault;
40152
+ vault = res.account;
40153
+ } else {
40154
+ throw new Error("resolveExponentStripContext: one of `vault` or `market` is required");
40155
+ }
40156
+ const altResult = await connection.getAddressLookupTable(vault.addressLookupTable);
40157
+ const alt = altResult.value;
40158
+ if (!alt) {
40159
+ throw new Error(
40160
+ `Exponent vault address lookup table not found: ${vault.addressLookupTable.toBase58()}`
40161
+ );
40162
+ }
40163
+ const remainingAccounts = resolveCpiMetas(
40164
+ vault.cpiAccounts.depositSy,
40165
+ alt.state.addresses,
40166
+ vault.addressLookupTable
40167
+ );
40168
+ const sySrc = getAssociatedTokenAddressSync(vault.mintSy, owner, true, syTokenProgram);
40169
+ const ptDst = getAssociatedTokenAddressSync(vault.mintPt, owner, true, ptYtTokenProgram);
40170
+ const ytDst = getAssociatedTokenAddressSync(vault.mintYt, owner, true, ptYtTokenProgram);
40171
+ const stripAccounts = {
40172
+ depositor: owner,
40173
+ authority: vault.authority,
40174
+ vault: vaultAddress,
40175
+ sySrc,
40176
+ escrowSy: vault.escrowSy,
40177
+ ytDst,
40178
+ ptDst,
40179
+ mintYt: vault.mintYt,
40180
+ mintPt: vault.mintPt,
40181
+ syProgram: vault.syProgram,
40182
+ addressLookupTable: vault.addressLookupTable,
40183
+ yieldPosition: vault.yieldPosition,
40184
+ tokenProgram: ptYtTokenProgram,
40185
+ remainingAccounts
40186
+ };
40187
+ const [syDecimals, ptDecimals] = await Promise.all([
40188
+ getMintDecimals(connection, vault.mintSy),
40189
+ getMintDecimals(connection, vault.mintPt)
40190
+ ]);
40191
+ const syExchangeRate = vault.lastSeenSyExchangeRate.toNumber();
40192
+ return {
40193
+ vaultAddress,
40194
+ vault,
40195
+ stripAccounts,
40196
+ addressLookupTable: alt,
40197
+ sy: { mint: vault.mintSy, decimals: syDecimals, tokenProgram: syTokenProgram },
40198
+ pt: { mint: vault.mintPt, decimals: ptDecimals, tokenProgram: ptYtTokenProgram },
40199
+ yt: { mint: vault.mintYt, tokenProgram: ptYtTokenProgram },
40200
+ syExchangeRate,
40201
+ computeStrippedPtNative(syInNative) {
40202
+ const pt = vault.lastSeenSyExchangeRate.times(syInNative.toString()).integerValue(bignumber_js.BigNumber.ROUND_FLOOR);
40203
+ return BigInt(pt.toFixed(0));
40204
+ }
40205
+ };
40206
+ }
40207
+ async function resolveSplStakePoolRefreshIx(connection, stakePool) {
40208
+ const info = await connection.getAccountInfo(stakePool);
40209
+ if (!info) throw new Error(`SPL stake pool account not found: ${stakePool.toBase58()}`);
40210
+ const stakePoolProgram = info.owner;
40211
+ const at = (off) => new web3_js.PublicKey(info.data.subarray(off, off + 32));
40212
+ const [withdrawAuthority] = web3_js.PublicKey.findProgramAddressSync(
40213
+ [stakePool.toBuffer(), Buffer.from("withdraw")],
40214
+ stakePoolProgram
40215
+ );
40216
+ return makeSplStakePoolUpdateBalanceIx({
40217
+ stakePoolProgram,
40218
+ stakePool,
40219
+ withdrawAuthority,
40220
+ validatorList: at(STAKE_POOL_OFFSETS.validatorList),
40221
+ reserveStake: at(STAKE_POOL_OFFSETS.reserveStake),
40222
+ managerFeeAccount: at(STAKE_POOL_OFFSETS.managerFeeAccount),
40223
+ poolMint: at(STAKE_POOL_OFFSETS.poolMint)
39867
40224
  });
39868
40225
  }
40226
+ async function resolveExponentWrapperMergeContext(params) {
40227
+ const { connection, owner, baseMint } = params;
40228
+ const ptYtTokenProgram = params.ptYtTokenProgram ?? TOKEN_PROGRAM_ID;
40229
+ const syTokenProgram = params.syTokenProgram ?? TOKEN_PROGRAM_ID;
40230
+ const baseTokenProgram = params.baseTokenProgram ?? TOKEN_PROGRAM_ID;
40231
+ let vaultAddress;
40232
+ let vault;
40233
+ if (params.vault) {
40234
+ vaultAddress = params.vault;
40235
+ vault = await fetchExponentVault(connection, vaultAddress);
40236
+ } else if (params.market) {
40237
+ const res = await fetchExponentVaultFromMarket(connection, params.market);
40238
+ vaultAddress = res.vault;
40239
+ vault = res.account;
40240
+ } else {
40241
+ throw new Error("resolveExponentWrapperMergeContext: one of `vault` or `market` is required");
40242
+ }
40243
+ const altResult = await connection.getAddressLookupTable(vault.addressLookupTable);
40244
+ const alt = altResult.value;
40245
+ if (!alt) {
40246
+ throw new Error(
40247
+ `Exponent vault address lookup table not found: ${vault.addressLookupTable.toBase58()}`
40248
+ );
40249
+ }
40250
+ const altKey = vault.addressLookupTable;
40251
+ const getSyState = resolveCpiMetas(vault.cpiAccounts.getSyState, alt.state.addresses, altKey);
40252
+ const withdrawSy = resolveCpiMetas(vault.cpiAccounts.withdrawSy, alt.state.addresses, altKey);
40253
+ if (getSyState.length < 4) {
40254
+ throw new Error(
40255
+ "resolveExponentWrapperMergeContext: unexpected get_sy_state shape (expected the generic SPL-stake-pool flavor: [syState, mintSy, tokenSyEscrow, stakePool])"
40256
+ );
40257
+ }
40258
+ const syState = getSyState[0].pubkey;
40259
+ const stakePool = getSyState[3].pubkey;
40260
+ const syAta = getAssociatedTokenAddressSync(vault.mintSy, owner, true, syTokenProgram);
40261
+ const ptAta = getAssociatedTokenAddressSync(vault.mintPt, owner, true, ptYtTokenProgram);
40262
+ const ytAta = getAssociatedTokenAddressSync(vault.mintYt, owner, true, ptYtTokenProgram);
40263
+ const baseAta = getAssociatedTokenAddressSync(baseMint, owner, true, baseTokenProgram);
40264
+ const baseEscrow = getAssociatedTokenAddressSync(baseMint, syState, true, baseTokenProgram);
40265
+ const redeem = [
40266
+ { pubkey: owner, isSigner: true, isWritable: true },
40267
+ { pubkey: syState, isSigner: false, isWritable: true },
40268
+ { pubkey: baseAta, isSigner: false, isWritable: true },
40269
+ { pubkey: baseEscrow, isSigner: false, isWritable: true },
40270
+ { pubkey: syAta, isSigner: false, isWritable: true },
40271
+ { pubkey: vault.mintSy, isSigner: false, isWritable: true },
40272
+ { pubkey: baseMint, isSigner: false, isWritable: false },
40273
+ { pubkey: syTokenProgram, isSigner: false, isWritable: false },
40274
+ { pubkey: baseTokenProgram, isSigner: false, isWritable: false },
40275
+ { pubkey: stakePool, isSigner: false, isWritable: true }
40276
+ ];
40277
+ const cpi = uniqueRemainingAccounts([...withdrawSy, ...getSyState]);
40278
+ const wrapperMergeAccounts = {
40279
+ owner,
40280
+ syAta,
40281
+ vault: vaultAddress,
40282
+ escrowSy: vault.escrowSy,
40283
+ ytAta,
40284
+ ptAta,
40285
+ mintYt: vault.mintYt,
40286
+ mintPt: vault.mintPt,
40287
+ authority: vault.authority,
40288
+ addressLookupTable: vault.addressLookupTable,
40289
+ yieldPosition: vault.yieldPosition,
40290
+ syProgram: vault.syProgram,
40291
+ tokenProgram: ptYtTokenProgram,
40292
+ remainingAccounts: [...redeem, ...cpi],
40293
+ redeemSyAccountsUntil: redeem.length
40294
+ };
40295
+ const [baseDecimals, stakePoolRefreshIx] = await Promise.all([
40296
+ getMintDecimals(connection, baseMint),
40297
+ resolveSplStakePoolRefreshIx(connection, stakePool)
40298
+ ]);
40299
+ return {
40300
+ vaultAddress,
40301
+ vault,
40302
+ wrapperMergeAccounts,
40303
+ preInstructions: [stakePoolRefreshIx],
40304
+ addressLookupTable: alt,
40305
+ baseToken: { mint: baseMint, decimals: baseDecimals, tokenProgram: baseTokenProgram },
40306
+ setupMints: [
40307
+ { mint: baseMint, tokenProgram: baseTokenProgram },
40308
+ { mint: vault.mintSy, tokenProgram: syTokenProgram },
40309
+ { mint: vault.mintPt, tokenProgram: ptYtTokenProgram },
40310
+ { mint: vault.mintYt, tokenProgram: ptYtTokenProgram }
40311
+ ],
40312
+ computeRedeemedBaseNative(ptAmountNative) {
40313
+ if (vault.ptSupply === 0n) return 0n;
40314
+ const base = new bignumber_js.BigNumber(ptAmountNative.toString()).times(vault.syForPt.toString()).div(vault.ptSupply.toString()).integerValue(bignumber_js.BigNumber.ROUND_FLOOR);
40315
+ return BigInt(base.toFixed(0));
40316
+ }
40317
+ };
40318
+ }
39869
40319
 
39870
40320
  exports.ACCOUNT_SIZE = ACCOUNT_SIZE;
39871
40321
  exports.ACCOUNT_TYPE_SIZE = ACCOUNT_TYPE_SIZE;
@@ -39879,12 +40329,18 @@ exports.DEFAULT_RECENT_SLOT_DURATION_MS = DEFAULT_RECENT_SLOT_DURATION_MS;
39879
40329
  exports.DRIFT_IDL = DRIFT_IDL;
39880
40330
  exports.DRIFT_PROGRAM_ID = DRIFT_PROGRAM_ID;
39881
40331
  exports.DriftSpotBalanceType = DriftSpotBalanceType;
40332
+ exports.EXPONENT_CLMM_PROGRAM_ID = EXPONENT_CLMM_PROGRAM_ID;
39882
40333
  exports.EXPONENT_CORE_IDL = EXPONENT_CORE_IDL;
39883
40334
  exports.EXPONENT_CORE_PROGRAM_ID = EXPONENT_CORE_PROGRAM_ID;
39884
40335
  exports.EXPONENT_EVENT_AUTHORITY_SEED = EXPONENT_EVENT_AUTHORITY_SEED;
39885
- exports.EXPONENT_LOCALNET_PROGRAM_ID = EXPONENT_LOCALNET_PROGRAM_ID;
40336
+ exports.EXPONENT_GENERIC_SY_PROGRAM_ID = EXPONENT_GENERIC_SY_PROGRAM_ID;
40337
+ exports.EXPONENT_JITO_RESTAKING_SY_PROGRAM_ID = EXPONENT_JITO_RESTAKING_SY_PROGRAM_ID;
40338
+ exports.EXPONENT_KAMINO_SY_PROGRAM_ID = EXPONENT_KAMINO_SY_PROGRAM_ID;
40339
+ exports.EXPONENT_MARGINFI_SY_PROGRAM_ID = EXPONENT_MARGINFI_SY_PROGRAM_ID;
39886
40340
  exports.EXPONENT_NUMBER_DENOM = EXPONENT_NUMBER_DENOM;
39887
- exports.EXPONENT_WRAPPER_PROGRAM_ID = EXPONENT_WRAPPER_PROGRAM_ID;
40341
+ exports.EXPONENT_ORDERBOOK_PROGRAM_ID = EXPONENT_ORDERBOOK_PROGRAM_ID;
40342
+ exports.EXPONENT_PERENA_SY_PROGRAM_ID = EXPONENT_PERENA_SY_PROGRAM_ID;
40343
+ exports.EXPONENT_VAULTS_PROGRAM_ID = EXPONENT_VAULTS_PROGRAM_ID;
39888
40344
  exports.ErrorResponse = ErrorResponse;
39889
40345
  exports.ExtensionType = ExtensionType;
39890
40346
  exports.FARMS_PROGRAM_ID = FARMS_PROGRAM_ID;
@@ -40019,6 +40475,7 @@ exports.decodeDriftSpotMarketData = decodeDriftSpotMarketData;
40019
40475
  exports.decodeDriftStateData = decodeDriftStateData;
40020
40476
  exports.decodeDriftUserData = decodeDriftUserData;
40021
40477
  exports.decodeDriftUserStatsData = decodeDriftUserStatsData;
40478
+ exports.decodeExponentMarketTwo = decodeExponentMarketTwo;
40022
40479
  exports.decodeExponentMarketVault = decodeExponentMarketVault;
40023
40480
  exports.decodeExponentVault = decodeExponentVault;
40024
40481
  exports.decodeFarmDataRaw = decodeFarmDataRaw;
@@ -40079,8 +40536,10 @@ exports.dtoToJupTokenReserveRaw = dtoToJupTokenReserveRaw;
40079
40536
  exports.dtoToObligationRaw = dtoToObligationRaw;
40080
40537
  exports.dtoToReserveRaw = dtoToReserveRaw;
40081
40538
  exports.encodeTitanTemplate = encodeTitanTemplate;
40539
+ exports.exponentBuyPtArgs = exponentBuyPtArgs;
40082
40540
  exports.exponentNumberToBigNumber = exponentNumberToBigNumber;
40083
40541
  exports.farmRawToDto = farmRawToDto;
40542
+ exports.fetchExponentMarketTwo = fetchExponentMarketTwo;
40084
40543
  exports.fetchExponentVault = fetchExponentVault;
40085
40544
  exports.fetchExponentVaultFromMarket = fetchExponentVaultFromMarket;
40086
40545
  exports.fetchTitanQuoteSwapV3 = fetchTitanQuoteSwapV3;
@@ -40132,9 +40591,13 @@ exports.jupTokenReserveRawToDto = jupTokenReserveRawToDto;
40132
40591
  exports.layout = layout;
40133
40592
  exports.lutToTitanWire = lutToTitanWire;
40134
40593
  exports.makeExponentMergeIx = makeExponentMergeIx;
40594
+ exports.makeExponentStripIx = makeExponentStripIx;
40595
+ exports.makeExponentTradePtIx = makeExponentTradePtIx;
40596
+ exports.makeExponentWrapperMergeIx = makeExponentWrapperMergeIx;
40135
40597
  exports.makeRefreshObligationIx = makeRefreshObligationIx;
40136
40598
  exports.makeRefreshReservesBatchIx = makeRefreshReservesBatchIx;
40137
40599
  exports.makeRefreshingIxs = makeRefreshingIxs;
40600
+ exports.makeSplStakePoolUpdateBalanceIx = makeSplStakePoolUpdateBalanceIx;
40138
40601
  exports.makeUpdateJupLendRate = makeUpdateJupLendRate;
40139
40602
  exports.makeUpdateJupLendRateIx = makeUpdateJupLendRateIx;
40140
40603
  exports.makeUpdateSpotMarketCumulativeInterestIx = makeUpdateSpotMarketCumulativeInterestIx;
@@ -40145,6 +40608,9 @@ exports.parsePriceInfo = parsePriceInfo2;
40145
40608
  exports.replenishPoolIx = replenishPoolIx;
40146
40609
  exports.reserveRawToDto = reserveRawToDto;
40147
40610
  exports.resolveExponentMergeContext = resolveExponentMergeContext;
40611
+ exports.resolveExponentStripContext = resolveExponentStripContext;
40612
+ exports.resolveExponentTradePtContext = resolveExponentTradePtContext;
40613
+ exports.resolveExponentWrapperMergeContext = resolveExponentWrapperMergeContext;
40148
40614
  exports.resolveLookupTables = resolveLookupTables;
40149
40615
  exports.scaledSupplies = scaledSupplies;
40150
40616
  exports.selectBestRoute = selectBestRoute;