@whetstone-research/doppler-sdk 1.0.27 → 1.0.29

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.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkU6B52TBT_cjs = require('./chunk-U6B52TBT.cjs');
3
+ var chunk4CI2M2F6_cjs = require('./chunk-4CI2M2F6.cjs');
4
4
  var kit = require('@solana/kit');
5
5
  var programClientCore = require('@solana/program-client-core');
6
6
 
@@ -50,7 +50,7 @@ var ammConfigDataCodec = kit.getStructCodec([
50
50
  ["admin", addressCodec],
51
51
  ["paused", boolCodec],
52
52
  ["hookAllowlistLen", u8Codec],
53
- ["hookAllowlist", kit.getArrayCodec(addressCodec, { size: chunkU6B52TBT_cjs.MAX_HOOK_ALLOWLIST })],
53
+ ["hookAllowlist", kit.getArrayCodec(addressCodec, { size: chunk4CI2M2F6_cjs.MAX_HOOK_ALLOWLIST })],
54
54
  ["maxSwapFeeBps", u16Codec],
55
55
  ["maxFeeSplitBps", u16Codec],
56
56
  ["protocolFeeEnabled", boolCodec],
@@ -113,22 +113,22 @@ var oracleStateDataCodec = kit.getStructCodec([
113
113
  ["observationIndex", u16Codec],
114
114
  [
115
115
  "observations",
116
- kit.getArrayCodec(observationCodec, { size: chunkU6B52TBT_cjs.MAX_ORACLE_OBSERVATIONS })
116
+ kit.getArrayCodec(observationCodec, { size: chunk4CI2M2F6_cjs.MAX_ORACLE_OBSERVATIONS })
117
117
  ],
118
118
  ["version", u8Codec],
119
119
  ["reserved", reservedBytesCodec]
120
120
  ]);
121
121
  var ammConfigDecoder = kit.getHiddenPrefixDecoder(ammConfigDataCodec, [
122
- kit.getConstantDecoder(chunkU6B52TBT_cjs.ACCOUNT_DISCRIMINATORS.AmmConfig)
122
+ kit.getConstantDecoder(chunk4CI2M2F6_cjs.ACCOUNT_DISCRIMINATORS.AmmConfig)
123
123
  ]);
124
124
  var poolDecoder = kit.getHiddenPrefixDecoder(poolDataCodec, [
125
- kit.getConstantDecoder(chunkU6B52TBT_cjs.ACCOUNT_DISCRIMINATORS.Pool)
125
+ kit.getConstantDecoder(chunk4CI2M2F6_cjs.ACCOUNT_DISCRIMINATORS.Pool)
126
126
  ]);
127
127
  var positionDecoder = kit.getHiddenPrefixDecoder(positionDataCodec, [
128
- kit.getConstantDecoder(chunkU6B52TBT_cjs.ACCOUNT_DISCRIMINATORS.Position)
128
+ kit.getConstantDecoder(chunk4CI2M2F6_cjs.ACCOUNT_DISCRIMINATORS.Position)
129
129
  ]);
130
130
  var oracleStateDecoder = kit.getHiddenPrefixDecoder(oracleStateDataCodec, [
131
- kit.getConstantDecoder(chunkU6B52TBT_cjs.ACCOUNT_DISCRIMINATORS.OracleState)
131
+ kit.getConstantDecoder(chunk4CI2M2F6_cjs.ACCOUNT_DISCRIMINATORS.OracleState)
132
132
  ]);
133
133
  function decodeAmmConfig(data) {
134
134
  return ammConfigDecoder.decode(data);
@@ -264,17 +264,96 @@ function encodeTransferAdminArgs(args) {
264
264
  function encodeOracleConsultArgs(args) {
265
265
  return new Uint8Array(oracleConsultArgsCodec.encode(args));
266
266
  }
267
+ function isObject(value) {
268
+ return typeof value === "object" && value !== null;
269
+ }
270
+ function isTransactionSigner(value) {
271
+ return isObject(value) && "address" in value && "signTransactions" in value;
272
+ }
273
+ function getAddressFromAddressOrSigner(value) {
274
+ return isTransactionSigner(value) ? value.address : value;
275
+ }
276
+ function getAddressFromRemainingAccount(account) {
277
+ if (typeof account === "string") {
278
+ return account;
279
+ }
280
+ return account.address;
281
+ }
282
+ function createAccountMeta(value, role) {
283
+ if (isTransactionSigner(value)) {
284
+ return { address: value.address, role, signer: value };
285
+ }
286
+ return { address: value, role };
287
+ }
288
+ function createReadonlyRemainingAccountMeta(account) {
289
+ if (typeof account === "string") {
290
+ return { address: account, role: kit.AccountRole.READONLY };
291
+ }
292
+ if (isTransactionSigner(account)) {
293
+ return {
294
+ address: account.address,
295
+ role: kit.AccountRole.READONLY_SIGNER,
296
+ signer: account
297
+ };
298
+ }
299
+ return account;
300
+ }
301
+ function bytesToBase64(bytes) {
302
+ let binary = "";
303
+ for (let i = 0; i < bytes.length; i++) {
304
+ binary += String.fromCharCode(bytes[i]);
305
+ }
306
+ return btoa(binary);
307
+ }
308
+ function bytesToBase64EncodedBytes(bytes) {
309
+ return bytesToBase64(bytes);
310
+ }
311
+ function base64ToBytes(base64) {
312
+ const binary = atob(base64);
313
+ const bytes = new Uint8Array(binary.length);
314
+ for (let i = 0; i < binary.length; i++) {
315
+ bytes[i] = binary.charCodeAt(i);
316
+ }
317
+ return bytes;
318
+ }
319
+ function addressToBase58EncodedBytes(address) {
320
+ return address;
321
+ }
322
+ function isEncodedProgramAccount(account) {
323
+ if (!isObject(account) || typeof account.pubkey !== "string") {
324
+ return false;
325
+ }
326
+ const accountData = account.account;
327
+ if (!isObject(accountData) || !Array.isArray(accountData.data)) {
328
+ return false;
329
+ }
330
+ const [encodedData, encoding] = accountData.data;
331
+ return typeof encodedData === "string" && encoding === "base64";
332
+ }
333
+ function normalizeProgramAccountsResponse(response) {
334
+ const accounts = Array.isArray(response) ? response : isObject(response) && Array.isArray(response.value) ? response.value : null;
335
+ if (!accounts) {
336
+ throw new Error("Unexpected getProgramAccounts response shape");
337
+ }
338
+ if (!accounts.every(isEncodedProgramAccount)) {
339
+ throw new Error("Unexpected getProgramAccounts account shape");
340
+ }
341
+ return accounts;
342
+ }
343
+ function warnAccountDecodeFailure(accountType, accountAddress) {
344
+ console.warn(`Failed to decode ${accountType} account: ${accountAddress}`);
345
+ }
267
346
 
268
347
  // src/solana/core/math.ts
269
348
  function q64ToNumber(q64) {
270
349
  const intPart = q64 >> 64n;
271
350
  const fracPart = q64 & (1n << 64n) - 1n;
272
- return Number(intPart) + Number(fracPart) / Number(chunkU6B52TBT_cjs.Q64_ONE);
351
+ return Number(intPart) + Number(fracPart) / Number(chunk4CI2M2F6_cjs.Q64_ONE);
273
352
  }
274
353
  function numberToQ64(n) {
275
354
  const intPart = Math.floor(n);
276
355
  const fracPart = n - intPart;
277
- return (BigInt(intPart) << 64n) + BigInt(Math.round(fracPart * Number(chunkU6B52TBT_cjs.Q64_ONE)));
356
+ return (BigInt(intPart) << 64n) + BigInt(Math.round(fracPart * Number(chunk4CI2M2F6_cjs.Q64_ONE)));
278
357
  }
279
358
  function q64Mul(a, b) {
280
359
  return a * b >> 64n;
@@ -330,8 +409,8 @@ function getSwapQuote(pool, amountIn, tradeDirection) {
330
409
  if (reserveIn === 0n || reserveOut === 0n) {
331
410
  throw new Error("Pool has zero liquidity");
332
411
  }
333
- const feeTotal = amountIn * BigInt(pool.swapFeeBps) / chunkU6B52TBT_cjs.BPS_DENOM;
334
- const feeDist = feeTotal * BigInt(pool.feeSplitBps) / chunkU6B52TBT_cjs.BPS_DENOM;
412
+ const feeTotal = amountIn * BigInt(pool.swapFeeBps) / chunk4CI2M2F6_cjs.BPS_DENOM;
413
+ const feeDist = feeTotal * BigInt(pool.feeSplitBps) / chunk4CI2M2F6_cjs.BPS_DENOM;
335
414
  const feeComp = feeTotal - feeDist;
336
415
  const amountInEff = amountIn - feeTotal;
337
416
  const amountOut = amountInEff * reserveOut / (reserveIn + amountInEff);
@@ -357,8 +436,8 @@ function getSwapQuoteExactOut(pool, amountOut, tradeDirection) {
357
436
  }
358
437
  const amountInEff = ceilDiv(amountOut * reserveIn, reserveOut - amountOut);
359
438
  const amountIn = ceilDiv(
360
- amountInEff * chunkU6B52TBT_cjs.BPS_DENOM,
361
- chunkU6B52TBT_cjs.BPS_DENOM - BigInt(pool.swapFeeBps)
439
+ amountInEff * chunk4CI2M2F6_cjs.BPS_DENOM,
440
+ chunk4CI2M2F6_cjs.BPS_DENOM - BigInt(pool.swapFeeBps)
362
441
  );
363
442
  const feeTotal = amountIn - amountInEff;
364
443
  return { amountIn, feeTotal };
@@ -1620,6 +1699,298 @@ function parseInitializePoolInstruction(instruction) {
1620
1699
  data: getInitializePoolInstructionDataDecoder().decode(instruction.data)
1621
1700
  };
1622
1701
  }
1702
+ var INITIALIZE_SPOT_POOL_DISCRIMINATOR = new Uint8Array([
1703
+ 254,
1704
+ 243,
1705
+ 84,
1706
+ 29,
1707
+ 237,
1708
+ 165,
1709
+ 241,
1710
+ 217
1711
+ ]);
1712
+ function getInitializeSpotPoolDiscriminatorBytes() {
1713
+ return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(
1714
+ INITIALIZE_SPOT_POOL_DISCRIMINATOR
1715
+ );
1716
+ }
1717
+ function getInitializeSpotPoolInstructionDataEncoder() {
1718
+ return kit.transformEncoder(
1719
+ kit.getStructEncoder([
1720
+ ["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)],
1721
+ ["mintA", kit.getAddressEncoder()],
1722
+ ["mintB", kit.getAddressEncoder()],
1723
+ ["swapFeeBps", kit.getU16Encoder()]
1724
+ ]),
1725
+ (value) => ({
1726
+ ...value,
1727
+ discriminator: INITIALIZE_SPOT_POOL_DISCRIMINATOR
1728
+ })
1729
+ );
1730
+ }
1731
+ function getInitializeSpotPoolInstructionDataDecoder() {
1732
+ return kit.getStructDecoder([
1733
+ ["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)],
1734
+ ["mintA", kit.getAddressDecoder()],
1735
+ ["mintB", kit.getAddressDecoder()],
1736
+ ["swapFeeBps", kit.getU16Decoder()]
1737
+ ]);
1738
+ }
1739
+ function getInitializeSpotPoolInstructionDataCodec() {
1740
+ return kit.combineCodec(
1741
+ getInitializeSpotPoolInstructionDataEncoder(),
1742
+ getInitializeSpotPoolInstructionDataDecoder()
1743
+ );
1744
+ }
1745
+ async function getInitializeSpotPoolInstructionAsync(input, config) {
1746
+ const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
1747
+ const originalAccounts = {
1748
+ config: { value: input.config ?? null, isWritable: false },
1749
+ pool: { value: input.pool ?? null, isWritable: true },
1750
+ protocolFeePosition: {
1751
+ value: input.protocolFeePosition ?? null,
1752
+ isWritable: true
1753
+ },
1754
+ protocolFeeOwner: {
1755
+ value: input.protocolFeeOwner ?? null,
1756
+ isWritable: false
1757
+ },
1758
+ authority: { value: input.authority ?? null, isWritable: false },
1759
+ vault0: { value: input.vault0 ?? null, isWritable: true },
1760
+ vault1: { value: input.vault1 ?? null, isWritable: true },
1761
+ token0Mint: { value: input.token0Mint ?? null, isWritable: false },
1762
+ token1Mint: { value: input.token1Mint ?? null, isWritable: false },
1763
+ payer: { value: input.payer ?? null, isWritable: true },
1764
+ token0Program: { value: input.token0Program ?? null, isWritable: false },
1765
+ token1Program: { value: input.token1Program ?? null, isWritable: false },
1766
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
1767
+ rent: { value: input.rent ?? null, isWritable: false },
1768
+ migrationAuthority: {
1769
+ value: input.migrationAuthority ?? null,
1770
+ isWritable: false
1771
+ }
1772
+ };
1773
+ const accounts = originalAccounts;
1774
+ const args = { ...input };
1775
+ if (!accounts.protocolFeeOwner.value) {
1776
+ accounts.protocolFeeOwner.value = await kit.getProgramDerivedAddress({
1777
+ programAddress,
1778
+ seeds: [
1779
+ kit.getBytesEncoder().encode(
1780
+ new Uint8Array([
1781
+ 112,
1782
+ 114,
1783
+ 111,
1784
+ 116,
1785
+ 111,
1786
+ 99,
1787
+ 111,
1788
+ 108,
1789
+ 95,
1790
+ 102,
1791
+ 101,
1792
+ 101,
1793
+ 95,
1794
+ 111,
1795
+ 119,
1796
+ 110,
1797
+ 101,
1798
+ 114
1799
+ ])
1800
+ ),
1801
+ kit.getAddressEncoder().encode(
1802
+ programClientCore.getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
1803
+ )
1804
+ ]
1805
+ });
1806
+ }
1807
+ if (!accounts.protocolFeePosition.value) {
1808
+ accounts.protocolFeePosition.value = await kit.getProgramDerivedAddress({
1809
+ programAddress,
1810
+ seeds: [
1811
+ kit.getBytesEncoder().encode(
1812
+ new Uint8Array([112, 111, 115, 105, 116, 105, 111, 110])
1813
+ ),
1814
+ kit.getAddressEncoder().encode(
1815
+ programClientCore.getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
1816
+ ),
1817
+ kit.getAddressEncoder().encode(
1818
+ programClientCore.getAddressFromResolvedInstructionAccount(
1819
+ "protocolFeeOwner",
1820
+ accounts.protocolFeeOwner.value
1821
+ )
1822
+ ),
1823
+ kit.getBytesEncoder().encode(new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0]))
1824
+ ]
1825
+ });
1826
+ }
1827
+ if (!accounts.authority.value) {
1828
+ accounts.authority.value = await kit.getProgramDerivedAddress({
1829
+ programAddress,
1830
+ seeds: [
1831
+ kit.getBytesEncoder().encode(
1832
+ new Uint8Array([97, 117, 116, 104, 111, 114, 105, 116, 121])
1833
+ ),
1834
+ kit.getAddressEncoder().encode(
1835
+ programClientCore.getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
1836
+ )
1837
+ ]
1838
+ });
1839
+ }
1840
+ if (!accounts.vault0.value) {
1841
+ accounts.vault0.value = await kit.getProgramDerivedAddress({
1842
+ programAddress,
1843
+ seeds: [
1844
+ kit.getBytesEncoder().encode(new Uint8Array([118, 97, 117, 108, 116, 48])),
1845
+ kit.getAddressEncoder().encode(
1846
+ programClientCore.getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
1847
+ )
1848
+ ]
1849
+ });
1850
+ }
1851
+ if (!accounts.vault1.value) {
1852
+ accounts.vault1.value = await kit.getProgramDerivedAddress({
1853
+ programAddress,
1854
+ seeds: [
1855
+ kit.getBytesEncoder().encode(new Uint8Array([118, 97, 117, 108, 116, 49])),
1856
+ kit.getAddressEncoder().encode(
1857
+ programClientCore.getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
1858
+ )
1859
+ ]
1860
+ });
1861
+ }
1862
+ if (!accounts.systemProgram.value) {
1863
+ accounts.systemProgram.value = "11111111111111111111111111111111";
1864
+ }
1865
+ if (!accounts.rent.value) {
1866
+ accounts.rent.value = "SysvarRent111111111111111111111111111111111";
1867
+ }
1868
+ const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
1869
+ return Object.freeze({
1870
+ accounts: [
1871
+ getAccountMeta("config", accounts.config),
1872
+ getAccountMeta("pool", accounts.pool),
1873
+ getAccountMeta("protocolFeePosition", accounts.protocolFeePosition),
1874
+ getAccountMeta("protocolFeeOwner", accounts.protocolFeeOwner),
1875
+ getAccountMeta("authority", accounts.authority),
1876
+ getAccountMeta("vault0", accounts.vault0),
1877
+ getAccountMeta("vault1", accounts.vault1),
1878
+ getAccountMeta("token0Mint", accounts.token0Mint),
1879
+ getAccountMeta("token1Mint", accounts.token1Mint),
1880
+ getAccountMeta("payer", accounts.payer),
1881
+ getAccountMeta("token0Program", accounts.token0Program),
1882
+ getAccountMeta("token1Program", accounts.token1Program),
1883
+ getAccountMeta("systemProgram", accounts.systemProgram),
1884
+ getAccountMeta("rent", accounts.rent),
1885
+ getAccountMeta("migrationAuthority", accounts.migrationAuthority)
1886
+ ],
1887
+ data: getInitializeSpotPoolInstructionDataEncoder().encode(
1888
+ args
1889
+ ),
1890
+ programAddress
1891
+ });
1892
+ }
1893
+ function getInitializeSpotPoolInstruction(input, config) {
1894
+ const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
1895
+ const originalAccounts = {
1896
+ config: { value: input.config ?? null, isWritable: false },
1897
+ pool: { value: input.pool ?? null, isWritable: true },
1898
+ protocolFeePosition: {
1899
+ value: input.protocolFeePosition ?? null,
1900
+ isWritable: true
1901
+ },
1902
+ protocolFeeOwner: {
1903
+ value: input.protocolFeeOwner ?? null,
1904
+ isWritable: false
1905
+ },
1906
+ authority: { value: input.authority ?? null, isWritable: false },
1907
+ vault0: { value: input.vault0 ?? null, isWritable: true },
1908
+ vault1: { value: input.vault1 ?? null, isWritable: true },
1909
+ token0Mint: { value: input.token0Mint ?? null, isWritable: false },
1910
+ token1Mint: { value: input.token1Mint ?? null, isWritable: false },
1911
+ payer: { value: input.payer ?? null, isWritable: true },
1912
+ token0Program: { value: input.token0Program ?? null, isWritable: false },
1913
+ token1Program: { value: input.token1Program ?? null, isWritable: false },
1914
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
1915
+ rent: { value: input.rent ?? null, isWritable: false },
1916
+ migrationAuthority: {
1917
+ value: input.migrationAuthority ?? null,
1918
+ isWritable: false
1919
+ }
1920
+ };
1921
+ const accounts = originalAccounts;
1922
+ const args = { ...input };
1923
+ if (!accounts.systemProgram.value) {
1924
+ accounts.systemProgram.value = "11111111111111111111111111111111";
1925
+ }
1926
+ if (!accounts.rent.value) {
1927
+ accounts.rent.value = "SysvarRent111111111111111111111111111111111";
1928
+ }
1929
+ const getAccountMeta = programClientCore.getAccountMetaFactory(programAddress, "programId");
1930
+ return Object.freeze({
1931
+ accounts: [
1932
+ getAccountMeta("config", accounts.config),
1933
+ getAccountMeta("pool", accounts.pool),
1934
+ getAccountMeta("protocolFeePosition", accounts.protocolFeePosition),
1935
+ getAccountMeta("protocolFeeOwner", accounts.protocolFeeOwner),
1936
+ getAccountMeta("authority", accounts.authority),
1937
+ getAccountMeta("vault0", accounts.vault0),
1938
+ getAccountMeta("vault1", accounts.vault1),
1939
+ getAccountMeta("token0Mint", accounts.token0Mint),
1940
+ getAccountMeta("token1Mint", accounts.token1Mint),
1941
+ getAccountMeta("payer", accounts.payer),
1942
+ getAccountMeta("token0Program", accounts.token0Program),
1943
+ getAccountMeta("token1Program", accounts.token1Program),
1944
+ getAccountMeta("systemProgram", accounts.systemProgram),
1945
+ getAccountMeta("rent", accounts.rent),
1946
+ getAccountMeta("migrationAuthority", accounts.migrationAuthority)
1947
+ ],
1948
+ data: getInitializeSpotPoolInstructionDataEncoder().encode(
1949
+ args
1950
+ ),
1951
+ programAddress
1952
+ });
1953
+ }
1954
+ function parseInitializeSpotPoolInstruction(instruction) {
1955
+ if (instruction.accounts.length < 15) {
1956
+ throw new kit.SolanaError(
1957
+ kit.SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
1958
+ {
1959
+ actualAccountMetas: instruction.accounts.length,
1960
+ expectedAccountMetas: 15
1961
+ }
1962
+ );
1963
+ }
1964
+ let accountIndex = 0;
1965
+ const getNextAccount = () => {
1966
+ const accountMeta = instruction.accounts[accountIndex];
1967
+ accountIndex += 1;
1968
+ return accountMeta;
1969
+ };
1970
+ return {
1971
+ programAddress: instruction.programAddress,
1972
+ accounts: {
1973
+ config: getNextAccount(),
1974
+ pool: getNextAccount(),
1975
+ protocolFeePosition: getNextAccount(),
1976
+ protocolFeeOwner: getNextAccount(),
1977
+ authority: getNextAccount(),
1978
+ vault0: getNextAccount(),
1979
+ vault1: getNextAccount(),
1980
+ token0Mint: getNextAccount(),
1981
+ token1Mint: getNextAccount(),
1982
+ payer: getNextAccount(),
1983
+ token0Program: getNextAccount(),
1984
+ token1Program: getNextAccount(),
1985
+ systemProgram: getNextAccount(),
1986
+ rent: getNextAccount(),
1987
+ migrationAuthority: getNextAccount()
1988
+ },
1989
+ data: getInitializeSpotPoolInstructionDataDecoder().decode(
1990
+ instruction.data
1991
+ )
1992
+ };
1993
+ }
1623
1994
  var ORACLE_CONSULT_DISCRIMINATOR = new Uint8Array([
1624
1995
  239,
1625
1996
  237,
@@ -3352,21 +3723,6 @@ function parseAddLiquidityInstruction(instruction) {
3352
3723
  }
3353
3724
 
3354
3725
  // src/solana/client/pool.ts
3355
- function bytesToBase64(bytes) {
3356
- let binary = "";
3357
- for (let i = 0; i < bytes.length; i++) {
3358
- binary += String.fromCharCode(bytes[i]);
3359
- }
3360
- return btoa(binary);
3361
- }
3362
- function base64ToBytes(base64) {
3363
- const binary = atob(base64);
3364
- const bytes = new Uint8Array(binary.length);
3365
- for (let i = 0; i < binary.length; i++) {
3366
- bytes[i] = binary.charCodeAt(i);
3367
- }
3368
- return bytes;
3369
- }
3370
3726
  async function fetchPool(rpc, address, config) {
3371
3727
  const response = await rpc.getAccountInfo(address, {
3372
3728
  encoding: "base64",
@@ -3378,11 +3734,11 @@ async function fetchPool(rpc, address, config) {
3378
3734
  return decodePool(base64ToBytes(response.value.data[0]));
3379
3735
  }
3380
3736
  async function fetchAllPools(rpc, config) {
3381
- const programId = config?.programId ?? chunkU6B52TBT_cjs.CPMM_PROGRAM_ID;
3737
+ const programId = config?.programId ?? chunk4CI2M2F6_cjs.CPMM_PROGRAM_ID;
3382
3738
  const discriminatorFilter = {
3383
3739
  memcmp: {
3384
3740
  offset: 0n,
3385
- bytes: bytesToBase64(chunkU6B52TBT_cjs.ACCOUNT_DISCRIMINATORS.Pool),
3741
+ bytes: bytesToBase64EncodedBytes(chunk4CI2M2F6_cjs.ACCOUNT_DISCRIMINATORS.Pool),
3386
3742
  encoding: "base64"
3387
3743
  }
3388
3744
  };
@@ -3391,7 +3747,7 @@ async function fetchAllPools(rpc, config) {
3391
3747
  commitment: config?.commitment,
3392
3748
  filters: [discriminatorFilter]
3393
3749
  }).send();
3394
- const accounts = Array.isArray(response) ? response : response.value;
3750
+ const accounts = normalizeProgramAccountsResponse(response);
3395
3751
  const pools = [];
3396
3752
  for (const account of accounts) {
3397
3753
  try {
@@ -3401,14 +3757,14 @@ async function fetchAllPools(rpc, config) {
3401
3757
  account: pool
3402
3758
  });
3403
3759
  } catch {
3404
- console.warn(`Failed to decode pool account: ${account.pubkey}`);
3760
+ warnAccountDecodeFailure("pool", account.pubkey);
3405
3761
  }
3406
3762
  }
3407
3763
  return pools;
3408
3764
  }
3409
3765
  async function getPoolByMints(rpc, mint0, mint1, config) {
3410
- const programId = config?.programId ?? chunkU6B52TBT_cjs.CPMM_PROGRAM_ID;
3411
- const [poolAddress] = await chunkU6B52TBT_cjs.getPoolAddress(mint0, mint1, programId);
3766
+ const programId = config?.programId ?? chunk4CI2M2F6_cjs.CPMM_PROGRAM_ID;
3767
+ const [poolAddress] = await chunk4CI2M2F6_cjs.getPoolAddress(mint0, mint1, programId);
3412
3768
  const pool = await fetchPool(rpc, poolAddress, config);
3413
3769
  if (!pool) {
3414
3770
  return null;
@@ -3435,9 +3791,9 @@ async function poolExists(rpc, mint0, mint1, config) {
3435
3791
  const result = await getPoolByMints(rpc, mint0, mint1, config);
3436
3792
  return result !== null;
3437
3793
  }
3438
- async function getPoolAddressFromMints(mint0, mint1, programId = chunkU6B52TBT_cjs.CPMM_PROGRAM_ID) {
3439
- const [token0, token1] = chunkU6B52TBT_cjs.sortMints(mint0, mint1);
3440
- const [poolAddress] = await chunkU6B52TBT_cjs.getPoolAddress(mint0, mint1, programId);
3794
+ async function getPoolAddressFromMints(mint0, mint1, programId = chunk4CI2M2F6_cjs.CPMM_PROGRAM_ID) {
3795
+ const [token0, token1] = chunk4CI2M2F6_cjs.sortMints(mint0, mint1);
3796
+ const [poolAddress] = await chunk4CI2M2F6_cjs.getPoolAddress(mint0, mint1, programId);
3441
3797
  return {
3442
3798
  poolAddress,
3443
3799
  token0,
@@ -3459,21 +3815,6 @@ function sortPoolsByReserves(pools, descending = true) {
3459
3815
  }
3460
3816
 
3461
3817
  // src/solana/client/position.ts
3462
- function bytesToBase642(bytes) {
3463
- let binary = "";
3464
- for (let i = 0; i < bytes.length; i++) {
3465
- binary += String.fromCharCode(bytes[i]);
3466
- }
3467
- return btoa(binary);
3468
- }
3469
- function base64ToBytes2(base64) {
3470
- const binary = atob(base64);
3471
- const bytes = new Uint8Array(binary.length);
3472
- for (let i = 0; i < binary.length; i++) {
3473
- bytes[i] = binary.charCodeAt(i);
3474
- }
3475
- return bytes;
3476
- }
3477
3818
  async function fetchPosition(rpc, address, config) {
3478
3819
  const response = await rpc.getAccountInfo(address, {
3479
3820
  encoding: "base64",
@@ -3482,18 +3823,16 @@ async function fetchPosition(rpc, address, config) {
3482
3823
  if (!response.value) {
3483
3824
  return null;
3484
3825
  }
3485
- return decodePosition(base64ToBytes2(response.value.data[0]));
3826
+ return decodePosition(base64ToBytes(response.value.data[0]));
3486
3827
  }
3487
3828
  async function fetchUserPositions(rpc, owner, pool, config) {
3488
- const programId = config?.programId ?? chunkU6B52TBT_cjs.CPMM_PROGRAM_ID;
3829
+ const programId = config?.programId ?? chunk4CI2M2F6_cjs.CPMM_PROGRAM_ID;
3489
3830
  const filters = [
3490
3831
  // Discriminator filter (first 8 bytes)
3491
3832
  {
3492
3833
  memcmp: {
3493
3834
  offset: 0n,
3494
- bytes: bytesToBase642(
3495
- chunkU6B52TBT_cjs.ACCOUNT_DISCRIMINATORS.Position
3496
- ),
3835
+ bytes: bytesToBase64EncodedBytes(chunk4CI2M2F6_cjs.ACCOUNT_DISCRIMINATORS.Position),
3497
3836
  encoding: "base64"
3498
3837
  }
3499
3838
  },
@@ -3501,7 +3840,7 @@ async function fetchUserPositions(rpc, owner, pool, config) {
3501
3840
  {
3502
3841
  memcmp: {
3503
3842
  offset: 40n,
3504
- bytes: owner,
3843
+ bytes: addressToBase58EncodedBytes(owner),
3505
3844
  encoding: "base58"
3506
3845
  }
3507
3846
  }
@@ -3510,7 +3849,7 @@ async function fetchUserPositions(rpc, owner, pool, config) {
3510
3849
  filters.push({
3511
3850
  memcmp: {
3512
3851
  offset: 8n,
3513
- bytes: pool,
3852
+ bytes: addressToBase58EncodedBytes(pool),
3514
3853
  encoding: "base58"
3515
3854
  }
3516
3855
  });
@@ -3520,31 +3859,29 @@ async function fetchUserPositions(rpc, owner, pool, config) {
3520
3859
  commitment: config?.commitment,
3521
3860
  filters
3522
3861
  }).send();
3523
- const accounts = Array.isArray(response) ? response : response.value;
3862
+ const accounts = normalizeProgramAccountsResponse(response);
3524
3863
  const positions = [];
3525
3864
  for (const account of accounts) {
3526
3865
  try {
3527
- const position = decodePosition(base64ToBytes2(account.account.data[0]));
3866
+ const position = decodePosition(base64ToBytes(account.account.data[0]));
3528
3867
  positions.push({
3529
3868
  address: account.pubkey,
3530
3869
  account: position
3531
3870
  });
3532
3871
  } catch {
3533
- console.warn(`Failed to decode position account: ${account.pubkey}`);
3872
+ warnAccountDecodeFailure("position", account.pubkey);
3534
3873
  }
3535
3874
  }
3536
3875
  return positions;
3537
3876
  }
3538
3877
  async function fetchPoolPositions(rpc, pool, config) {
3539
- const programId = config?.programId ?? chunkU6B52TBT_cjs.CPMM_PROGRAM_ID;
3878
+ const programId = config?.programId ?? chunk4CI2M2F6_cjs.CPMM_PROGRAM_ID;
3540
3879
  const filters = [
3541
3880
  // Discriminator filter
3542
3881
  {
3543
3882
  memcmp: {
3544
3883
  offset: 0n,
3545
- bytes: bytesToBase642(
3546
- chunkU6B52TBT_cjs.ACCOUNT_DISCRIMINATORS.Position
3547
- ),
3884
+ bytes: bytesToBase64EncodedBytes(chunk4CI2M2F6_cjs.ACCOUNT_DISCRIMINATORS.Position),
3548
3885
  encoding: "base64"
3549
3886
  }
3550
3887
  },
@@ -3552,7 +3889,7 @@ async function fetchPoolPositions(rpc, pool, config) {
3552
3889
  {
3553
3890
  memcmp: {
3554
3891
  offset: 8n,
3555
- bytes: pool,
3892
+ bytes: addressToBase58EncodedBytes(pool),
3556
3893
  encoding: "base58"
3557
3894
  }
3558
3895
  }
@@ -3562,17 +3899,17 @@ async function fetchPoolPositions(rpc, pool, config) {
3562
3899
  commitment: config?.commitment,
3563
3900
  filters
3564
3901
  }).send();
3565
- const accounts = Array.isArray(response) ? response : response.value;
3902
+ const accounts = normalizeProgramAccountsResponse(response);
3566
3903
  const positions = [];
3567
3904
  for (const account of accounts) {
3568
3905
  try {
3569
- const position = decodePosition(base64ToBytes2(account.account.data[0]));
3906
+ const position = decodePosition(base64ToBytes(account.account.data[0]));
3570
3907
  positions.push({
3571
3908
  address: account.pubkey,
3572
3909
  account: position
3573
3910
  });
3574
3911
  } catch {
3575
- console.warn(`Failed to decode position account: ${account.pubkey}`);
3912
+ warnAccountDecodeFailure("position", account.pubkey);
3576
3913
  }
3577
3914
  }
3578
3915
  return positions;
@@ -3604,8 +3941,8 @@ function getPositionValue(pool, position) {
3604
3941
  };
3605
3942
  }
3606
3943
  async function fetchPositionByParams(rpc, pool, owner, positionId, config) {
3607
- const programId = config?.programId ?? chunkU6B52TBT_cjs.CPMM_PROGRAM_ID;
3608
- const [address] = await chunkU6B52TBT_cjs.getPositionAddress(
3944
+ const programId = config?.programId ?? chunk4CI2M2F6_cjs.CPMM_PROGRAM_ID;
3945
+ const [address] = await chunk4CI2M2F6_cjs.getPositionAddress(
3609
3946
  pool,
3610
3947
  owner,
3611
3948
  positionId,
@@ -3620,8 +3957,8 @@ async function fetchPositionByParams(rpc, pool, owner, positionId, config) {
3620
3957
  account: position
3621
3958
  };
3622
3959
  }
3623
- async function getPositionAddressFromParams(pool, owner, positionId, programId = chunkU6B52TBT_cjs.CPMM_PROGRAM_ID) {
3624
- const [address] = await chunkU6B52TBT_cjs.getPositionAddress(
3960
+ async function getPositionAddressFromParams(pool, owner, positionId, programId = chunk4CI2M2F6_cjs.CPMM_PROGRAM_ID) {
3961
+ const [address] = await chunk4CI2M2F6_cjs.getPositionAddress(
3625
3962
  pool,
3626
3963
  owner,
3627
3964
  positionId,
@@ -3653,14 +3990,6 @@ function sortPositionsByShares(positions, descending = true) {
3653
3990
  }
3654
3991
 
3655
3992
  // src/solana/client/oracle.ts
3656
- function base64ToBytes3(base64) {
3657
- const binary = atob(base64);
3658
- const bytes = new Uint8Array(binary.length);
3659
- for (let i = 0; i < binary.length; i++) {
3660
- bytes[i] = binary.charCodeAt(i);
3661
- }
3662
- return bytes;
3663
- }
3664
3993
  async function fetchOracle(rpc, address, config) {
3665
3994
  const response = await rpc.getAccountInfo(address, {
3666
3995
  encoding: "base64",
@@ -3669,11 +3998,11 @@ async function fetchOracle(rpc, address, config) {
3669
3998
  if (!response.value) {
3670
3999
  return null;
3671
4000
  }
3672
- return decodeOracleState(base64ToBytes3(response.value.data[0]));
4001
+ return decodeOracleState(base64ToBytes(response.value.data[0]));
3673
4002
  }
3674
4003
  async function getOracleForPool(rpc, pool, config) {
3675
- const programId = config?.programId ?? chunkU6B52TBT_cjs.CPMM_PROGRAM_ID;
3676
- const [oracleAddress] = await chunkU6B52TBT_cjs.getOracleAddress(pool, programId);
4004
+ const programId = config?.programId ?? chunk4CI2M2F6_cjs.CPMM_PROGRAM_ID;
4005
+ const [oracleAddress] = await chunk4CI2M2F6_cjs.getOracleAddress(pool, programId);
3677
4006
  const oracle = await fetchOracle(rpc, oracleAddress, config);
3678
4007
  if (!oracle) {
3679
4008
  return null;
@@ -3683,8 +4012,8 @@ async function getOracleForPool(rpc, pool, config) {
3683
4012
  account: oracle
3684
4013
  };
3685
4014
  }
3686
- async function getOracleAddressFromPool(pool, programId = chunkU6B52TBT_cjs.CPMM_PROGRAM_ID) {
3687
- const [address] = await chunkU6B52TBT_cjs.getOracleAddress(pool, programId);
4015
+ async function getOracleAddressFromPool(pool, programId = chunk4CI2M2F6_cjs.CPMM_PROGRAM_ID) {
4016
+ const [address] = await chunk4CI2M2F6_cjs.getOracleAddress(pool, programId);
3688
4017
  return address;
3689
4018
  }
3690
4019
  function consultTwap(oracle, windowSeconds, currentTimestamp) {
@@ -3807,10 +4136,10 @@ function getOracleBufferStats(oracle) {
3807
4136
  };
3808
4137
  }
3809
4138
  async function fetchOraclesBatch(rpc, pools, config) {
3810
- const programId = config?.programId ?? chunkU6B52TBT_cjs.CPMM_PROGRAM_ID;
4139
+ const programId = config?.programId ?? chunk4CI2M2F6_cjs.CPMM_PROGRAM_ID;
3811
4140
  const oracles = /* @__PURE__ */ new Map();
3812
4141
  const oracleAddresses = await Promise.all(
3813
- pools.map((pool) => chunkU6B52TBT_cjs.getOracleAddress(pool, programId))
4142
+ pools.map((pool) => chunk4CI2M2F6_cjs.getOracleAddress(pool, programId))
3814
4143
  );
3815
4144
  const results = await Promise.all(
3816
4145
  oracleAddresses.map(([addr]) => fetchOracle(rpc, addr, config))
@@ -3846,6 +4175,7 @@ exports.CREATE_POSITION_DISCRIMINATOR = CREATE_POSITION_DISCRIMINATOR;
3846
4175
  exports.INITIALIZE_CONFIG_DISCRIMINATOR = INITIALIZE_CONFIG_DISCRIMINATOR;
3847
4176
  exports.INITIALIZE_ORACLE_DISCRIMINATOR = INITIALIZE_ORACLE_DISCRIMINATOR;
3848
4177
  exports.INITIALIZE_POOL_DISCRIMINATOR = INITIALIZE_POOL_DISCRIMINATOR;
4178
+ exports.INITIALIZE_SPOT_POOL_DISCRIMINATOR = INITIALIZE_SPOT_POOL_DISCRIMINATOR;
3849
4179
  exports.ORACLE_CONSULT_DISCRIMINATOR = ORACLE_CONSULT_DISCRIMINATOR;
3850
4180
  exports.ORACLE_UPDATE_DISCRIMINATOR = ORACLE_UPDATE_DISCRIMINATOR;
3851
4181
  exports.PAUSE_DISCRIMINATOR = PAUSE_DISCRIMINATOR;
@@ -3860,7 +4190,11 @@ exports.UNPAUSE_DISCRIMINATOR = UNPAUSE_DISCRIMINATOR;
3860
4190
  exports.UPDATE_CONFIG_DISCRIMINATOR = UPDATE_CONFIG_DISCRIMINATOR;
3861
4191
  exports.WITHDRAW_VAULT_EXCESS_DISCRIMINATOR = WITHDRAW_VAULT_EXCESS_DISCRIMINATOR;
3862
4192
  exports.addLiquidityArgsCodec = addLiquidityArgsCodec;
4193
+ exports.addressToBase58EncodedBytes = addressToBase58EncodedBytes;
3863
4194
  exports.ammConfigDataCodec = ammConfigDataCodec;
4195
+ exports.base64ToBytes = base64ToBytes;
4196
+ exports.bytesToBase64 = bytesToBase64;
4197
+ exports.bytesToBase64EncodedBytes = bytesToBase64EncodedBytes;
3864
4198
  exports.calculateAccruedFees = calculateAccruedFees;
3865
4199
  exports.calculateTwap = calculateTwap;
3866
4200
  exports.calculateTwapNumber = calculateTwapNumber;
@@ -3871,7 +4205,9 @@ exports.comparePoolAndOraclePrices = comparePoolAndOraclePrices;
3871
4205
  exports.computePrice0Q64 = computePrice0Q64;
3872
4206
  exports.computePrice1Q64 = computePrice1Q64;
3873
4207
  exports.consultTwap = consultTwap;
4208
+ exports.createAccountMeta = createAccountMeta;
3874
4209
  exports.createPositionArgsCodec = createPositionArgsCodec;
4210
+ exports.createReadonlyRemainingAccountMeta = createReadonlyRemainingAccountMeta;
3875
4211
  exports.decodeAmmConfig = decodeAmmConfig;
3876
4212
  exports.decodeOracleState = decodeOracleState;
3877
4213
  exports.decodePool = decodePool;
@@ -3909,6 +4245,8 @@ exports.getAddLiquidityInstructionDataCodec = getAddLiquidityInstructionDataCode
3909
4245
  exports.getAddLiquidityInstructionDataDecoder = getAddLiquidityInstructionDataDecoder;
3910
4246
  exports.getAddLiquidityInstructionDataEncoder = getAddLiquidityInstructionDataEncoder;
3911
4247
  exports.getAddLiquidityQuote = getAddLiquidityQuote;
4248
+ exports.getAddressFromAddressOrSigner = getAddressFromAddressOrSigner;
4249
+ exports.getAddressFromRemainingAccount = getAddressFromRemainingAccount;
3912
4250
  exports.getClosePositionDiscriminatorBytes = getClosePositionDiscriminatorBytes;
3913
4251
  exports.getClosePositionInstruction = getClosePositionInstruction;
3914
4252
  exports.getClosePositionInstructionDataCodec = getClosePositionInstructionDataCodec;
@@ -3950,6 +4288,12 @@ exports.getInitializePoolInstructionAsync = getInitializePoolInstructionAsync;
3950
4288
  exports.getInitializePoolInstructionDataCodec = getInitializePoolInstructionDataCodec;
3951
4289
  exports.getInitializePoolInstructionDataDecoder = getInitializePoolInstructionDataDecoder;
3952
4290
  exports.getInitializePoolInstructionDataEncoder = getInitializePoolInstructionDataEncoder;
4291
+ exports.getInitializeSpotPoolDiscriminatorBytes = getInitializeSpotPoolDiscriminatorBytes;
4292
+ exports.getInitializeSpotPoolInstruction = getInitializeSpotPoolInstruction;
4293
+ exports.getInitializeSpotPoolInstructionAsync = getInitializeSpotPoolInstructionAsync;
4294
+ exports.getInitializeSpotPoolInstructionDataCodec = getInitializeSpotPoolInstructionDataCodec;
4295
+ exports.getInitializeSpotPoolInstructionDataDecoder = getInitializeSpotPoolInstructionDataDecoder;
4296
+ exports.getInitializeSpotPoolInstructionDataEncoder = getInitializeSpotPoolInstructionDataEncoder;
3953
4297
  exports.getK = getK;
3954
4298
  exports.getOracleAddressFromPool = getOracleAddressFromPool;
3955
4299
  exports.getOracleAge = getOracleAge;
@@ -4043,9 +4387,11 @@ exports.initializeConfigArgsCodec = initializeConfigArgsCodec;
4043
4387
  exports.initializeOracleArgsCodec = initializeOracleArgsCodec;
4044
4388
  exports.initializePoolArgsCodec = initializePoolArgsCodec;
4045
4389
  exports.isOracleStale = isOracleStale;
4390
+ exports.isTransactionSigner = isTransactionSigner;
4046
4391
  exports.isqrt = isqrt;
4047
4392
  exports.maxBigInt = maxBigInt;
4048
4393
  exports.minBigInt = minBigInt;
4394
+ exports.normalizeProgramAccountsResponse = normalizeProgramAccountsResponse;
4049
4395
  exports.numberToQ64 = numberToQ64;
4050
4396
  exports.observationCodec = observationCodec;
4051
4397
  exports.oracleConsultArgsCodec = oracleConsultArgsCodec;
@@ -4058,6 +4404,7 @@ exports.parseCreatePositionInstruction = parseCreatePositionInstruction;
4058
4404
  exports.parseInitializeConfigInstruction = parseInitializeConfigInstruction;
4059
4405
  exports.parseInitializeOracleInstruction = parseInitializeOracleInstruction;
4060
4406
  exports.parseInitializePoolInstruction = parseInitializePoolInstruction;
4407
+ exports.parseInitializeSpotPoolInstruction = parseInitializeSpotPoolInstruction;
4061
4408
  exports.parseOracleConsultInstruction = parseOracleConsultInstruction;
4062
4409
  exports.parseOracleUpdateInstruction = parseOracleUpdateInstruction;
4063
4410
  exports.parsePauseInstruction = parsePauseInstruction;
@@ -4085,5 +4432,6 @@ exports.sortPoolsByReserves = sortPoolsByReserves;
4085
4432
  exports.sortPositionsByShares = sortPositionsByShares;
4086
4433
  exports.swapExactInArgsCodec = swapExactInArgsCodec;
4087
4434
  exports.transferAdminArgsCodec = transferAdminArgsCodec;
4088
- //# sourceMappingURL=chunk-XTL2GBZ4.cjs.map
4089
- //# sourceMappingURL=chunk-XTL2GBZ4.cjs.map
4435
+ exports.warnAccountDecodeFailure = warnAccountDecodeFailure;
4436
+ //# sourceMappingURL=chunk-7PXLEMBJ.cjs.map
4437
+ //# sourceMappingURL=chunk-7PXLEMBJ.cjs.map