@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,5 +1,5 @@
1
- import { MAX_HOOK_ALLOWLIST, MAX_ORACLE_OBSERVATIONS, ACCOUNT_DISCRIMINATORS, CPMM_PROGRAM_ID, Q64_ONE, BPS_DENOM, getPoolAddress, sortMints, getPositionAddress, getOracleAddress } from './chunk-WD5VOZGI.js';
2
- import { getAddressCodec, getBooleanCodec, getU8Codec, getU16Codec, getU32Codec, getU64Codec, getU128Codec, transformCodec, getArrayCodec, fixCodecSize, getBytesCodec, getStructCodec, getHiddenPrefixDecoder, getConstantDecoder, mergeBytes, fixEncoderSize, getBytesEncoder, transformEncoder, getStructEncoder, getStructDecoder, fixDecoderSize, getBytesDecoder, combineCodec, SolanaError, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, getU64Encoder, getU64Decoder, getProgramDerivedAddress, getAddressEncoder, getU16Encoder, getBooleanEncoder, getArrayEncoder, getAddressDecoder, getU16Decoder, getBooleanDecoder, getArrayDecoder, getU128Encoder, getU32Encoder, getU128Decoder, getU32Decoder, getU8Encoder, getU8Decoder } from '@solana/kit';
1
+ import { MAX_HOOK_ALLOWLIST, MAX_ORACLE_OBSERVATIONS, ACCOUNT_DISCRIMINATORS, CPMM_PROGRAM_ID, Q64_ONE, BPS_DENOM, getPoolAddress, sortMints, getPositionAddress, getOracleAddress } from './chunk-AFXFT3BD.js';
2
+ import { getAddressCodec, getBooleanCodec, getU8Codec, getU16Codec, getU32Codec, getU64Codec, getU128Codec, transformCodec, getArrayCodec, fixCodecSize, getBytesCodec, getStructCodec, getHiddenPrefixDecoder, getConstantDecoder, mergeBytes, AccountRole, fixEncoderSize, getBytesEncoder, transformEncoder, getStructEncoder, getStructDecoder, fixDecoderSize, getBytesDecoder, combineCodec, SolanaError, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, getU64Encoder, getU64Decoder, getProgramDerivedAddress, getAddressEncoder, getU16Encoder, getBooleanEncoder, getArrayEncoder, getAddressDecoder, getU16Decoder, getBooleanDecoder, getArrayDecoder, getU128Encoder, getU32Encoder, getU128Decoder, getU32Decoder, getU8Encoder, getU8Decoder } from '@solana/kit';
3
3
  import { getAccountMetaFactory, getAddressFromResolvedInstructionAccount, getNonNullResolvedInstructionInput } from '@solana/program-client-core';
4
4
 
5
5
  var addressCodec = getAddressCodec();
@@ -262,6 +262,85 @@ function encodeTransferAdminArgs(args) {
262
262
  function encodeOracleConsultArgs(args) {
263
263
  return new Uint8Array(oracleConsultArgsCodec.encode(args));
264
264
  }
265
+ function isObject(value) {
266
+ return typeof value === "object" && value !== null;
267
+ }
268
+ function isTransactionSigner(value) {
269
+ return isObject(value) && "address" in value && "signTransactions" in value;
270
+ }
271
+ function getAddressFromAddressOrSigner(value) {
272
+ return isTransactionSigner(value) ? value.address : value;
273
+ }
274
+ function getAddressFromRemainingAccount(account) {
275
+ if (typeof account === "string") {
276
+ return account;
277
+ }
278
+ return account.address;
279
+ }
280
+ function createAccountMeta(value, role) {
281
+ if (isTransactionSigner(value)) {
282
+ return { address: value.address, role, signer: value };
283
+ }
284
+ return { address: value, role };
285
+ }
286
+ function createReadonlyRemainingAccountMeta(account) {
287
+ if (typeof account === "string") {
288
+ return { address: account, role: AccountRole.READONLY };
289
+ }
290
+ if (isTransactionSigner(account)) {
291
+ return {
292
+ address: account.address,
293
+ role: AccountRole.READONLY_SIGNER,
294
+ signer: account
295
+ };
296
+ }
297
+ return account;
298
+ }
299
+ function bytesToBase64(bytes) {
300
+ let binary = "";
301
+ for (let i = 0; i < bytes.length; i++) {
302
+ binary += String.fromCharCode(bytes[i]);
303
+ }
304
+ return btoa(binary);
305
+ }
306
+ function bytesToBase64EncodedBytes(bytes) {
307
+ return bytesToBase64(bytes);
308
+ }
309
+ function base64ToBytes(base64) {
310
+ const binary = atob(base64);
311
+ const bytes = new Uint8Array(binary.length);
312
+ for (let i = 0; i < binary.length; i++) {
313
+ bytes[i] = binary.charCodeAt(i);
314
+ }
315
+ return bytes;
316
+ }
317
+ function addressToBase58EncodedBytes(address) {
318
+ return address;
319
+ }
320
+ function isEncodedProgramAccount(account) {
321
+ if (!isObject(account) || typeof account.pubkey !== "string") {
322
+ return false;
323
+ }
324
+ const accountData = account.account;
325
+ if (!isObject(accountData) || !Array.isArray(accountData.data)) {
326
+ return false;
327
+ }
328
+ const [encodedData, encoding] = accountData.data;
329
+ return typeof encodedData === "string" && encoding === "base64";
330
+ }
331
+ function normalizeProgramAccountsResponse(response) {
332
+ const accounts = Array.isArray(response) ? response : isObject(response) && Array.isArray(response.value) ? response.value : null;
333
+ if (!accounts) {
334
+ throw new Error("Unexpected getProgramAccounts response shape");
335
+ }
336
+ if (!accounts.every(isEncodedProgramAccount)) {
337
+ throw new Error("Unexpected getProgramAccounts account shape");
338
+ }
339
+ return accounts;
340
+ }
341
+ function warnAccountDecodeFailure(accountType, accountAddress) {
342
+ console.warn(`Failed to decode ${accountType} account: ${accountAddress}`);
343
+ }
265
344
 
266
345
  // src/solana/core/math.ts
267
346
  function q64ToNumber(q64) {
@@ -1618,6 +1697,298 @@ function parseInitializePoolInstruction(instruction) {
1618
1697
  data: getInitializePoolInstructionDataDecoder().decode(instruction.data)
1619
1698
  };
1620
1699
  }
1700
+ var INITIALIZE_SPOT_POOL_DISCRIMINATOR = new Uint8Array([
1701
+ 254,
1702
+ 243,
1703
+ 84,
1704
+ 29,
1705
+ 237,
1706
+ 165,
1707
+ 241,
1708
+ 217
1709
+ ]);
1710
+ function getInitializeSpotPoolDiscriminatorBytes() {
1711
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
1712
+ INITIALIZE_SPOT_POOL_DISCRIMINATOR
1713
+ );
1714
+ }
1715
+ function getInitializeSpotPoolInstructionDataEncoder() {
1716
+ return transformEncoder(
1717
+ getStructEncoder([
1718
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
1719
+ ["mintA", getAddressEncoder()],
1720
+ ["mintB", getAddressEncoder()],
1721
+ ["swapFeeBps", getU16Encoder()]
1722
+ ]),
1723
+ (value) => ({
1724
+ ...value,
1725
+ discriminator: INITIALIZE_SPOT_POOL_DISCRIMINATOR
1726
+ })
1727
+ );
1728
+ }
1729
+ function getInitializeSpotPoolInstructionDataDecoder() {
1730
+ return getStructDecoder([
1731
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
1732
+ ["mintA", getAddressDecoder()],
1733
+ ["mintB", getAddressDecoder()],
1734
+ ["swapFeeBps", getU16Decoder()]
1735
+ ]);
1736
+ }
1737
+ function getInitializeSpotPoolInstructionDataCodec() {
1738
+ return combineCodec(
1739
+ getInitializeSpotPoolInstructionDataEncoder(),
1740
+ getInitializeSpotPoolInstructionDataDecoder()
1741
+ );
1742
+ }
1743
+ async function getInitializeSpotPoolInstructionAsync(input, config) {
1744
+ const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
1745
+ const originalAccounts = {
1746
+ config: { value: input.config ?? null, isWritable: false },
1747
+ pool: { value: input.pool ?? null, isWritable: true },
1748
+ protocolFeePosition: {
1749
+ value: input.protocolFeePosition ?? null,
1750
+ isWritable: true
1751
+ },
1752
+ protocolFeeOwner: {
1753
+ value: input.protocolFeeOwner ?? null,
1754
+ isWritable: false
1755
+ },
1756
+ authority: { value: input.authority ?? null, isWritable: false },
1757
+ vault0: { value: input.vault0 ?? null, isWritable: true },
1758
+ vault1: { value: input.vault1 ?? null, isWritable: true },
1759
+ token0Mint: { value: input.token0Mint ?? null, isWritable: false },
1760
+ token1Mint: { value: input.token1Mint ?? null, isWritable: false },
1761
+ payer: { value: input.payer ?? null, isWritable: true },
1762
+ token0Program: { value: input.token0Program ?? null, isWritable: false },
1763
+ token1Program: { value: input.token1Program ?? null, isWritable: false },
1764
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
1765
+ rent: { value: input.rent ?? null, isWritable: false },
1766
+ migrationAuthority: {
1767
+ value: input.migrationAuthority ?? null,
1768
+ isWritable: false
1769
+ }
1770
+ };
1771
+ const accounts = originalAccounts;
1772
+ const args = { ...input };
1773
+ if (!accounts.protocolFeeOwner.value) {
1774
+ accounts.protocolFeeOwner.value = await getProgramDerivedAddress({
1775
+ programAddress,
1776
+ seeds: [
1777
+ getBytesEncoder().encode(
1778
+ new Uint8Array([
1779
+ 112,
1780
+ 114,
1781
+ 111,
1782
+ 116,
1783
+ 111,
1784
+ 99,
1785
+ 111,
1786
+ 108,
1787
+ 95,
1788
+ 102,
1789
+ 101,
1790
+ 101,
1791
+ 95,
1792
+ 111,
1793
+ 119,
1794
+ 110,
1795
+ 101,
1796
+ 114
1797
+ ])
1798
+ ),
1799
+ getAddressEncoder().encode(
1800
+ getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
1801
+ )
1802
+ ]
1803
+ });
1804
+ }
1805
+ if (!accounts.protocolFeePosition.value) {
1806
+ accounts.protocolFeePosition.value = await getProgramDerivedAddress({
1807
+ programAddress,
1808
+ seeds: [
1809
+ getBytesEncoder().encode(
1810
+ new Uint8Array([112, 111, 115, 105, 116, 105, 111, 110])
1811
+ ),
1812
+ getAddressEncoder().encode(
1813
+ getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
1814
+ ),
1815
+ getAddressEncoder().encode(
1816
+ getAddressFromResolvedInstructionAccount(
1817
+ "protocolFeeOwner",
1818
+ accounts.protocolFeeOwner.value
1819
+ )
1820
+ ),
1821
+ getBytesEncoder().encode(new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0]))
1822
+ ]
1823
+ });
1824
+ }
1825
+ if (!accounts.authority.value) {
1826
+ accounts.authority.value = await getProgramDerivedAddress({
1827
+ programAddress,
1828
+ seeds: [
1829
+ getBytesEncoder().encode(
1830
+ new Uint8Array([97, 117, 116, 104, 111, 114, 105, 116, 121])
1831
+ ),
1832
+ getAddressEncoder().encode(
1833
+ getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
1834
+ )
1835
+ ]
1836
+ });
1837
+ }
1838
+ if (!accounts.vault0.value) {
1839
+ accounts.vault0.value = await getProgramDerivedAddress({
1840
+ programAddress,
1841
+ seeds: [
1842
+ getBytesEncoder().encode(new Uint8Array([118, 97, 117, 108, 116, 48])),
1843
+ getAddressEncoder().encode(
1844
+ getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
1845
+ )
1846
+ ]
1847
+ });
1848
+ }
1849
+ if (!accounts.vault1.value) {
1850
+ accounts.vault1.value = await getProgramDerivedAddress({
1851
+ programAddress,
1852
+ seeds: [
1853
+ getBytesEncoder().encode(new Uint8Array([118, 97, 117, 108, 116, 49])),
1854
+ getAddressEncoder().encode(
1855
+ getAddressFromResolvedInstructionAccount("pool", accounts.pool.value)
1856
+ )
1857
+ ]
1858
+ });
1859
+ }
1860
+ if (!accounts.systemProgram.value) {
1861
+ accounts.systemProgram.value = "11111111111111111111111111111111";
1862
+ }
1863
+ if (!accounts.rent.value) {
1864
+ accounts.rent.value = "SysvarRent111111111111111111111111111111111";
1865
+ }
1866
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
1867
+ return Object.freeze({
1868
+ accounts: [
1869
+ getAccountMeta("config", accounts.config),
1870
+ getAccountMeta("pool", accounts.pool),
1871
+ getAccountMeta("protocolFeePosition", accounts.protocolFeePosition),
1872
+ getAccountMeta("protocolFeeOwner", accounts.protocolFeeOwner),
1873
+ getAccountMeta("authority", accounts.authority),
1874
+ getAccountMeta("vault0", accounts.vault0),
1875
+ getAccountMeta("vault1", accounts.vault1),
1876
+ getAccountMeta("token0Mint", accounts.token0Mint),
1877
+ getAccountMeta("token1Mint", accounts.token1Mint),
1878
+ getAccountMeta("payer", accounts.payer),
1879
+ getAccountMeta("token0Program", accounts.token0Program),
1880
+ getAccountMeta("token1Program", accounts.token1Program),
1881
+ getAccountMeta("systemProgram", accounts.systemProgram),
1882
+ getAccountMeta("rent", accounts.rent),
1883
+ getAccountMeta("migrationAuthority", accounts.migrationAuthority)
1884
+ ],
1885
+ data: getInitializeSpotPoolInstructionDataEncoder().encode(
1886
+ args
1887
+ ),
1888
+ programAddress
1889
+ });
1890
+ }
1891
+ function getInitializeSpotPoolInstruction(input, config) {
1892
+ const programAddress = config?.programAddress ?? CPMM_PROGRAM_ADDRESS;
1893
+ const originalAccounts = {
1894
+ config: { value: input.config ?? null, isWritable: false },
1895
+ pool: { value: input.pool ?? null, isWritable: true },
1896
+ protocolFeePosition: {
1897
+ value: input.protocolFeePosition ?? null,
1898
+ isWritable: true
1899
+ },
1900
+ protocolFeeOwner: {
1901
+ value: input.protocolFeeOwner ?? null,
1902
+ isWritable: false
1903
+ },
1904
+ authority: { value: input.authority ?? null, isWritable: false },
1905
+ vault0: { value: input.vault0 ?? null, isWritable: true },
1906
+ vault1: { value: input.vault1 ?? null, isWritable: true },
1907
+ token0Mint: { value: input.token0Mint ?? null, isWritable: false },
1908
+ token1Mint: { value: input.token1Mint ?? null, isWritable: false },
1909
+ payer: { value: input.payer ?? null, isWritable: true },
1910
+ token0Program: { value: input.token0Program ?? null, isWritable: false },
1911
+ token1Program: { value: input.token1Program ?? null, isWritable: false },
1912
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
1913
+ rent: { value: input.rent ?? null, isWritable: false },
1914
+ migrationAuthority: {
1915
+ value: input.migrationAuthority ?? null,
1916
+ isWritable: false
1917
+ }
1918
+ };
1919
+ const accounts = originalAccounts;
1920
+ const args = { ...input };
1921
+ if (!accounts.systemProgram.value) {
1922
+ accounts.systemProgram.value = "11111111111111111111111111111111";
1923
+ }
1924
+ if (!accounts.rent.value) {
1925
+ accounts.rent.value = "SysvarRent111111111111111111111111111111111";
1926
+ }
1927
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
1928
+ return Object.freeze({
1929
+ accounts: [
1930
+ getAccountMeta("config", accounts.config),
1931
+ getAccountMeta("pool", accounts.pool),
1932
+ getAccountMeta("protocolFeePosition", accounts.protocolFeePosition),
1933
+ getAccountMeta("protocolFeeOwner", accounts.protocolFeeOwner),
1934
+ getAccountMeta("authority", accounts.authority),
1935
+ getAccountMeta("vault0", accounts.vault0),
1936
+ getAccountMeta("vault1", accounts.vault1),
1937
+ getAccountMeta("token0Mint", accounts.token0Mint),
1938
+ getAccountMeta("token1Mint", accounts.token1Mint),
1939
+ getAccountMeta("payer", accounts.payer),
1940
+ getAccountMeta("token0Program", accounts.token0Program),
1941
+ getAccountMeta("token1Program", accounts.token1Program),
1942
+ getAccountMeta("systemProgram", accounts.systemProgram),
1943
+ getAccountMeta("rent", accounts.rent),
1944
+ getAccountMeta("migrationAuthority", accounts.migrationAuthority)
1945
+ ],
1946
+ data: getInitializeSpotPoolInstructionDataEncoder().encode(
1947
+ args
1948
+ ),
1949
+ programAddress
1950
+ });
1951
+ }
1952
+ function parseInitializeSpotPoolInstruction(instruction) {
1953
+ if (instruction.accounts.length < 15) {
1954
+ throw new SolanaError(
1955
+ SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
1956
+ {
1957
+ actualAccountMetas: instruction.accounts.length,
1958
+ expectedAccountMetas: 15
1959
+ }
1960
+ );
1961
+ }
1962
+ let accountIndex = 0;
1963
+ const getNextAccount = () => {
1964
+ const accountMeta = instruction.accounts[accountIndex];
1965
+ accountIndex += 1;
1966
+ return accountMeta;
1967
+ };
1968
+ return {
1969
+ programAddress: instruction.programAddress,
1970
+ accounts: {
1971
+ config: getNextAccount(),
1972
+ pool: getNextAccount(),
1973
+ protocolFeePosition: getNextAccount(),
1974
+ protocolFeeOwner: getNextAccount(),
1975
+ authority: getNextAccount(),
1976
+ vault0: getNextAccount(),
1977
+ vault1: getNextAccount(),
1978
+ token0Mint: getNextAccount(),
1979
+ token1Mint: getNextAccount(),
1980
+ payer: getNextAccount(),
1981
+ token0Program: getNextAccount(),
1982
+ token1Program: getNextAccount(),
1983
+ systemProgram: getNextAccount(),
1984
+ rent: getNextAccount(),
1985
+ migrationAuthority: getNextAccount()
1986
+ },
1987
+ data: getInitializeSpotPoolInstructionDataDecoder().decode(
1988
+ instruction.data
1989
+ )
1990
+ };
1991
+ }
1621
1992
  var ORACLE_CONSULT_DISCRIMINATOR = new Uint8Array([
1622
1993
  239,
1623
1994
  237,
@@ -3350,21 +3721,6 @@ function parseAddLiquidityInstruction(instruction) {
3350
3721
  }
3351
3722
 
3352
3723
  // src/solana/client/pool.ts
3353
- function bytesToBase64(bytes) {
3354
- let binary = "";
3355
- for (let i = 0; i < bytes.length; i++) {
3356
- binary += String.fromCharCode(bytes[i]);
3357
- }
3358
- return btoa(binary);
3359
- }
3360
- function base64ToBytes(base64) {
3361
- const binary = atob(base64);
3362
- const bytes = new Uint8Array(binary.length);
3363
- for (let i = 0; i < binary.length; i++) {
3364
- bytes[i] = binary.charCodeAt(i);
3365
- }
3366
- return bytes;
3367
- }
3368
3724
  async function fetchPool(rpc, address, config) {
3369
3725
  const response = await rpc.getAccountInfo(address, {
3370
3726
  encoding: "base64",
@@ -3380,7 +3736,7 @@ async function fetchAllPools(rpc, config) {
3380
3736
  const discriminatorFilter = {
3381
3737
  memcmp: {
3382
3738
  offset: 0n,
3383
- bytes: bytesToBase64(ACCOUNT_DISCRIMINATORS.Pool),
3739
+ bytes: bytesToBase64EncodedBytes(ACCOUNT_DISCRIMINATORS.Pool),
3384
3740
  encoding: "base64"
3385
3741
  }
3386
3742
  };
@@ -3389,7 +3745,7 @@ async function fetchAllPools(rpc, config) {
3389
3745
  commitment: config?.commitment,
3390
3746
  filters: [discriminatorFilter]
3391
3747
  }).send();
3392
- const accounts = Array.isArray(response) ? response : response.value;
3748
+ const accounts = normalizeProgramAccountsResponse(response);
3393
3749
  const pools = [];
3394
3750
  for (const account of accounts) {
3395
3751
  try {
@@ -3399,7 +3755,7 @@ async function fetchAllPools(rpc, config) {
3399
3755
  account: pool
3400
3756
  });
3401
3757
  } catch {
3402
- console.warn(`Failed to decode pool account: ${account.pubkey}`);
3758
+ warnAccountDecodeFailure("pool", account.pubkey);
3403
3759
  }
3404
3760
  }
3405
3761
  return pools;
@@ -3457,21 +3813,6 @@ function sortPoolsByReserves(pools, descending = true) {
3457
3813
  }
3458
3814
 
3459
3815
  // src/solana/client/position.ts
3460
- function bytesToBase642(bytes) {
3461
- let binary = "";
3462
- for (let i = 0; i < bytes.length; i++) {
3463
- binary += String.fromCharCode(bytes[i]);
3464
- }
3465
- return btoa(binary);
3466
- }
3467
- function base64ToBytes2(base64) {
3468
- const binary = atob(base64);
3469
- const bytes = new Uint8Array(binary.length);
3470
- for (let i = 0; i < binary.length; i++) {
3471
- bytes[i] = binary.charCodeAt(i);
3472
- }
3473
- return bytes;
3474
- }
3475
3816
  async function fetchPosition(rpc, address, config) {
3476
3817
  const response = await rpc.getAccountInfo(address, {
3477
3818
  encoding: "base64",
@@ -3480,7 +3821,7 @@ async function fetchPosition(rpc, address, config) {
3480
3821
  if (!response.value) {
3481
3822
  return null;
3482
3823
  }
3483
- return decodePosition(base64ToBytes2(response.value.data[0]));
3824
+ return decodePosition(base64ToBytes(response.value.data[0]));
3484
3825
  }
3485
3826
  async function fetchUserPositions(rpc, owner, pool, config) {
3486
3827
  const programId = config?.programId ?? CPMM_PROGRAM_ID;
@@ -3489,9 +3830,7 @@ async function fetchUserPositions(rpc, owner, pool, config) {
3489
3830
  {
3490
3831
  memcmp: {
3491
3832
  offset: 0n,
3492
- bytes: bytesToBase642(
3493
- ACCOUNT_DISCRIMINATORS.Position
3494
- ),
3833
+ bytes: bytesToBase64EncodedBytes(ACCOUNT_DISCRIMINATORS.Position),
3495
3834
  encoding: "base64"
3496
3835
  }
3497
3836
  },
@@ -3499,7 +3838,7 @@ async function fetchUserPositions(rpc, owner, pool, config) {
3499
3838
  {
3500
3839
  memcmp: {
3501
3840
  offset: 40n,
3502
- bytes: owner,
3841
+ bytes: addressToBase58EncodedBytes(owner),
3503
3842
  encoding: "base58"
3504
3843
  }
3505
3844
  }
@@ -3508,7 +3847,7 @@ async function fetchUserPositions(rpc, owner, pool, config) {
3508
3847
  filters.push({
3509
3848
  memcmp: {
3510
3849
  offset: 8n,
3511
- bytes: pool,
3850
+ bytes: addressToBase58EncodedBytes(pool),
3512
3851
  encoding: "base58"
3513
3852
  }
3514
3853
  });
@@ -3518,17 +3857,17 @@ async function fetchUserPositions(rpc, owner, pool, config) {
3518
3857
  commitment: config?.commitment,
3519
3858
  filters
3520
3859
  }).send();
3521
- const accounts = Array.isArray(response) ? response : response.value;
3860
+ const accounts = normalizeProgramAccountsResponse(response);
3522
3861
  const positions = [];
3523
3862
  for (const account of accounts) {
3524
3863
  try {
3525
- const position = decodePosition(base64ToBytes2(account.account.data[0]));
3864
+ const position = decodePosition(base64ToBytes(account.account.data[0]));
3526
3865
  positions.push({
3527
3866
  address: account.pubkey,
3528
3867
  account: position
3529
3868
  });
3530
3869
  } catch {
3531
- console.warn(`Failed to decode position account: ${account.pubkey}`);
3870
+ warnAccountDecodeFailure("position", account.pubkey);
3532
3871
  }
3533
3872
  }
3534
3873
  return positions;
@@ -3540,9 +3879,7 @@ async function fetchPoolPositions(rpc, pool, config) {
3540
3879
  {
3541
3880
  memcmp: {
3542
3881
  offset: 0n,
3543
- bytes: bytesToBase642(
3544
- ACCOUNT_DISCRIMINATORS.Position
3545
- ),
3882
+ bytes: bytesToBase64EncodedBytes(ACCOUNT_DISCRIMINATORS.Position),
3546
3883
  encoding: "base64"
3547
3884
  }
3548
3885
  },
@@ -3550,7 +3887,7 @@ async function fetchPoolPositions(rpc, pool, config) {
3550
3887
  {
3551
3888
  memcmp: {
3552
3889
  offset: 8n,
3553
- bytes: pool,
3890
+ bytes: addressToBase58EncodedBytes(pool),
3554
3891
  encoding: "base58"
3555
3892
  }
3556
3893
  }
@@ -3560,17 +3897,17 @@ async function fetchPoolPositions(rpc, pool, config) {
3560
3897
  commitment: config?.commitment,
3561
3898
  filters
3562
3899
  }).send();
3563
- const accounts = Array.isArray(response) ? response : response.value;
3900
+ const accounts = normalizeProgramAccountsResponse(response);
3564
3901
  const positions = [];
3565
3902
  for (const account of accounts) {
3566
3903
  try {
3567
- const position = decodePosition(base64ToBytes2(account.account.data[0]));
3904
+ const position = decodePosition(base64ToBytes(account.account.data[0]));
3568
3905
  positions.push({
3569
3906
  address: account.pubkey,
3570
3907
  account: position
3571
3908
  });
3572
3909
  } catch {
3573
- console.warn(`Failed to decode position account: ${account.pubkey}`);
3910
+ warnAccountDecodeFailure("position", account.pubkey);
3574
3911
  }
3575
3912
  }
3576
3913
  return positions;
@@ -3651,14 +3988,6 @@ function sortPositionsByShares(positions, descending = true) {
3651
3988
  }
3652
3989
 
3653
3990
  // src/solana/client/oracle.ts
3654
- function base64ToBytes3(base64) {
3655
- const binary = atob(base64);
3656
- const bytes = new Uint8Array(binary.length);
3657
- for (let i = 0; i < binary.length; i++) {
3658
- bytes[i] = binary.charCodeAt(i);
3659
- }
3660
- return bytes;
3661
- }
3662
3991
  async function fetchOracle(rpc, address, config) {
3663
3992
  const response = await rpc.getAccountInfo(address, {
3664
3993
  encoding: "base64",
@@ -3667,7 +3996,7 @@ async function fetchOracle(rpc, address, config) {
3667
3996
  if (!response.value) {
3668
3997
  return null;
3669
3998
  }
3670
- return decodeOracleState(base64ToBytes3(response.value.data[0]));
3999
+ return decodeOracleState(base64ToBytes(response.value.data[0]));
3671
4000
  }
3672
4001
  async function getOracleForPool(rpc, pool, config) {
3673
4002
  const programId = config?.programId ?? CPMM_PROGRAM_ID;
@@ -3835,6 +4164,6 @@ function comparePoolAndOraclePrices(pool, oracle) {
3835
4164
  };
3836
4165
  }
3837
4166
 
3838
- export { ADD_LIQUIDITY_DISCRIMINATOR, CLOSE_POSITION_DISCRIMINATOR, COLLECT_FEES_DISCRIMINATOR, COLLECT_PROTOCOL_FEES_DISCRIMINATOR, CPMM_PROGRAM_ADDRESS, CREATE_POSITION_DISCRIMINATOR, INITIALIZE_CONFIG_DISCRIMINATOR, INITIALIZE_ORACLE_DISCRIMINATOR, INITIALIZE_POOL_DISCRIMINATOR, ORACLE_CONSULT_DISCRIMINATOR, ORACLE_UPDATE_DISCRIMINATOR, PAUSE_DISCRIMINATOR, PREVIEW_SWAP_EXACT_IN_DISCRIMINATOR, REDEEM_PROTOCOL_SHARES_DISCRIMINATOR, REMOVE_LIQUIDITY_DISCRIMINATOR, SET_FEES_DISCRIMINATOR, SET_HOOK_DISCRIMINATOR, SWAP_EXACT_IN_DISCRIMINATOR, TRANSFER_ADMIN_DISCRIMINATOR, UNPAUSE_DISCRIMINATOR, UPDATE_CONFIG_DISCRIMINATOR, WITHDRAW_VAULT_EXCESS_DISCRIMINATOR, addLiquidityArgsCodec, ammConfigDataCodec, calculateAccruedFees, calculateTwap, calculateTwapNumber, ceilDiv, collectFeesArgsCodec, collectProtocolFeesArgsCodec, comparePoolAndOraclePrices, computePrice0Q64, computePrice1Q64, consultTwap, createPositionArgsCodec, decodeAmmConfig, decodeOracleState, decodePool, decodePosition, encodeAddLiquidityArgs, encodeCollectFeesArgs, encodeCollectProtocolFeesArgs, encodeCreatePositionArgs, encodeInitializeConfigArgs, encodeInitializeOracleArgs, encodeInitializePoolArgs, encodeInstructionData, encodeOracleConsultArgs, encodeRemoveLiquidityArgs, encodeSetFeesArgs, encodeSetHookArgs, encodeSwapExactInArgs, encodeTransferAdminArgs, fetchAllPools, fetchOracle, fetchOraclesBatch, fetchPool, fetchPoolPositions, fetchPoolsBatch, fetchPosition, fetchPositionByParams, fetchPositionsBatch, fetchUserPositions, filterActivePositions, filterPoolsByMint, getAddLiquidityDiscriminatorBytes, getAddLiquidityInstruction, getAddLiquidityInstructionAsync, getAddLiquidityInstructionDataCodec, getAddLiquidityInstructionDataDecoder, getAddLiquidityInstructionDataEncoder, getAddLiquidityQuote, getClosePositionDiscriminatorBytes, getClosePositionInstruction, getClosePositionInstructionDataCodec, getClosePositionInstructionDataDecoder, getClosePositionInstructionDataEncoder, getCollectFeesDiscriminatorBytes, getCollectFeesInstruction, getCollectFeesInstructionAsync, getCollectFeesInstructionDataCodec, getCollectFeesInstructionDataDecoder, getCollectFeesInstructionDataEncoder, getCollectProtocolFeesDiscriminatorBytes, getCollectProtocolFeesInstruction, getCollectProtocolFeesInstructionAsync, getCollectProtocolFeesInstructionDataCodec, getCollectProtocolFeesInstructionDataDecoder, getCollectProtocolFeesInstructionDataEncoder, getCreatePositionDiscriminatorBytes, getCreatePositionInstruction, getCreatePositionInstructionAsync, getCreatePositionInstructionDataCodec, getCreatePositionInstructionDataDecoder, getCreatePositionInstructionDataEncoder, getInitializeConfigDiscriminatorBytes, getInitializeConfigInstruction, getInitializeConfigInstructionAsync, getInitializeConfigInstructionDataCodec, getInitializeConfigInstructionDataDecoder, getInitializeConfigInstructionDataEncoder, getInitializeOracleDiscriminatorBytes, getInitializeOracleInstruction, getInitializeOracleInstructionAsync, getInitializeOracleInstructionDataCodec, getInitializeOracleInstructionDataDecoder, getInitializeOracleInstructionDataEncoder, getInitializePoolDiscriminatorBytes, getInitializePoolInstruction, getInitializePoolInstructionAsync, getInitializePoolInstructionDataCodec, getInitializePoolInstructionDataDecoder, getInitializePoolInstructionDataEncoder, getK, getOracleAddressFromPool, getOracleAge, getOracleBufferStats, getOracleConsultDiscriminatorBytes, getOracleConsultInstruction, getOracleConsultInstructionAsync, getOracleConsultInstructionDataCodec, getOracleConsultInstructionDataDecoder, getOracleConsultInstructionDataEncoder, getOracleDeviation, getOracleForPool, getOracleSpotPrices, getOracleUpdateDiscriminatorBytes, getOracleUpdateInstruction, getOracleUpdateInstructionAsync, getOracleUpdateInstructionDataCodec, getOracleUpdateInstructionDataDecoder, getOracleUpdateInstructionDataEncoder, getPauseDiscriminatorBytes, getPauseInstruction, getPauseInstructionDataCodec, getPauseInstructionDataDecoder, getPauseInstructionDataEncoder, getPendingFees, getPoolAddressFromMints, getPoolByMints, getPositionAddressFromParams, getPositionValue, getPreviewSwapExactInDiscriminatorBytes, getPreviewSwapExactInInstruction, getPreviewSwapExactInInstructionDataCodec, getPreviewSwapExactInInstructionDataDecoder, getPreviewSwapExactInInstructionDataEncoder, getRedeemProtocolSharesDiscriminatorBytes, getRedeemProtocolSharesInstruction, getRedeemProtocolSharesInstructionAsync, getRedeemProtocolSharesInstructionDataCodec, getRedeemProtocolSharesInstructionDataDecoder, getRedeemProtocolSharesInstructionDataEncoder, getRemoveLiquidityDiscriminatorBytes, getRemoveLiquidityInstruction, getRemoveLiquidityInstructionAsync, getRemoveLiquidityInstructionDataCodec, getRemoveLiquidityInstructionDataDecoder, getRemoveLiquidityInstructionDataEncoder, getRemoveLiquidityQuote, getSetFeesDiscriminatorBytes, getSetFeesInstruction, getSetFeesInstructionDataCodec, getSetFeesInstructionDataDecoder, getSetFeesInstructionDataEncoder, getSetHookDiscriminatorBytes, getSetHookInstruction, getSetHookInstructionDataCodec, getSetHookInstructionDataDecoder, getSetHookInstructionDataEncoder, getSpotPrice0, getSpotPrice1, getSwapExactInDiscriminatorBytes, getSwapExactInInstruction, getSwapExactInInstructionAsync, getSwapExactInInstructionDataCodec, getSwapExactInInstructionDataDecoder, getSwapExactInInstructionDataEncoder, getSwapQuote, getSwapQuoteExactOut, getTransferAdminDiscriminatorBytes, getTransferAdminInstruction, getTransferAdminInstructionDataCodec, getTransferAdminInstructionDataDecoder, getTransferAdminInstructionDataEncoder, getTvl, getUnpauseDiscriminatorBytes, getUnpauseInstruction, getUnpauseInstructionDataCodec, getUnpauseInstructionDataDecoder, getUnpauseInstructionDataEncoder, getUpdateConfigDiscriminatorBytes, getUpdateConfigInstruction, getUpdateConfigInstructionDataCodec, getUpdateConfigInstructionDataDecoder, getUpdateConfigInstructionDataEncoder, getWithdrawVaultExcessDiscriminatorBytes, getWithdrawVaultExcessInstruction, getWithdrawVaultExcessInstructionAsync, getWithdrawVaultExcessInstructionDataCodec, getWithdrawVaultExcessInstructionDataDecoder, getWithdrawVaultExcessInstructionDataEncoder, initializeConfigArgsCodec, initializeOracleArgsCodec, initializePoolArgsCodec, isOracleStale, isqrt, maxBigInt, minBigInt, numberToQ64, observationCodec, oracleConsultArgsCodec, oracleStateDataCodec, parseAddLiquidityInstruction, parseClosePositionInstruction, parseCollectFeesInstruction, parseCollectProtocolFeesInstruction, parseCreatePositionInstruction, parseInitializeConfigInstruction, parseInitializeOracleInstruction, parseInitializePoolInstruction, parseOracleConsultInstruction, parseOracleUpdateInstruction, parsePauseInstruction, parsePreviewSwapExactInInstruction, parseRedeemProtocolSharesInstruction, parseRemoveLiquidityInstruction, parseSetFeesInstruction, parseSetHookInstruction, parseSwapExactInInstruction, parseTransferAdminInstruction, parseUnpauseInstruction, parseUpdateConfigInstruction, parseWithdrawVaultExcessInstruction, poolDataCodec, poolExists, positionDataCodec, q64Div, q64Mul, q64ToNumber, ratioToNumber, removeLiquidityArgsCodec, setFeesArgsCodec, setHookArgsCodec, sortPoolsByReserves, sortPositionsByShares, swapExactInArgsCodec, transferAdminArgsCodec };
3839
- //# sourceMappingURL=chunk-RVDRWCJN.js.map
3840
- //# sourceMappingURL=chunk-RVDRWCJN.js.map
4167
+ export { ADD_LIQUIDITY_DISCRIMINATOR, CLOSE_POSITION_DISCRIMINATOR, COLLECT_FEES_DISCRIMINATOR, COLLECT_PROTOCOL_FEES_DISCRIMINATOR, CPMM_PROGRAM_ADDRESS, CREATE_POSITION_DISCRIMINATOR, INITIALIZE_CONFIG_DISCRIMINATOR, INITIALIZE_ORACLE_DISCRIMINATOR, INITIALIZE_POOL_DISCRIMINATOR, INITIALIZE_SPOT_POOL_DISCRIMINATOR, ORACLE_CONSULT_DISCRIMINATOR, ORACLE_UPDATE_DISCRIMINATOR, PAUSE_DISCRIMINATOR, PREVIEW_SWAP_EXACT_IN_DISCRIMINATOR, REDEEM_PROTOCOL_SHARES_DISCRIMINATOR, REMOVE_LIQUIDITY_DISCRIMINATOR, SET_FEES_DISCRIMINATOR, SET_HOOK_DISCRIMINATOR, SWAP_EXACT_IN_DISCRIMINATOR, TRANSFER_ADMIN_DISCRIMINATOR, UNPAUSE_DISCRIMINATOR, UPDATE_CONFIG_DISCRIMINATOR, WITHDRAW_VAULT_EXCESS_DISCRIMINATOR, addLiquidityArgsCodec, addressToBase58EncodedBytes, ammConfigDataCodec, base64ToBytes, bytesToBase64, bytesToBase64EncodedBytes, calculateAccruedFees, calculateTwap, calculateTwapNumber, ceilDiv, collectFeesArgsCodec, collectProtocolFeesArgsCodec, comparePoolAndOraclePrices, computePrice0Q64, computePrice1Q64, consultTwap, createAccountMeta, createPositionArgsCodec, createReadonlyRemainingAccountMeta, decodeAmmConfig, decodeOracleState, decodePool, decodePosition, encodeAddLiquidityArgs, encodeCollectFeesArgs, encodeCollectProtocolFeesArgs, encodeCreatePositionArgs, encodeInitializeConfigArgs, encodeInitializeOracleArgs, encodeInitializePoolArgs, encodeInstructionData, encodeOracleConsultArgs, encodeRemoveLiquidityArgs, encodeSetFeesArgs, encodeSetHookArgs, encodeSwapExactInArgs, encodeTransferAdminArgs, fetchAllPools, fetchOracle, fetchOraclesBatch, fetchPool, fetchPoolPositions, fetchPoolsBatch, fetchPosition, fetchPositionByParams, fetchPositionsBatch, fetchUserPositions, filterActivePositions, filterPoolsByMint, getAddLiquidityDiscriminatorBytes, getAddLiquidityInstruction, getAddLiquidityInstructionAsync, getAddLiquidityInstructionDataCodec, getAddLiquidityInstructionDataDecoder, getAddLiquidityInstructionDataEncoder, getAddLiquidityQuote, getAddressFromAddressOrSigner, getAddressFromRemainingAccount, getClosePositionDiscriminatorBytes, getClosePositionInstruction, getClosePositionInstructionDataCodec, getClosePositionInstructionDataDecoder, getClosePositionInstructionDataEncoder, getCollectFeesDiscriminatorBytes, getCollectFeesInstruction, getCollectFeesInstructionAsync, getCollectFeesInstructionDataCodec, getCollectFeesInstructionDataDecoder, getCollectFeesInstructionDataEncoder, getCollectProtocolFeesDiscriminatorBytes, getCollectProtocolFeesInstruction, getCollectProtocolFeesInstructionAsync, getCollectProtocolFeesInstructionDataCodec, getCollectProtocolFeesInstructionDataDecoder, getCollectProtocolFeesInstructionDataEncoder, getCreatePositionDiscriminatorBytes, getCreatePositionInstruction, getCreatePositionInstructionAsync, getCreatePositionInstructionDataCodec, getCreatePositionInstructionDataDecoder, getCreatePositionInstructionDataEncoder, getInitializeConfigDiscriminatorBytes, getInitializeConfigInstruction, getInitializeConfigInstructionAsync, getInitializeConfigInstructionDataCodec, getInitializeConfigInstructionDataDecoder, getInitializeConfigInstructionDataEncoder, getInitializeOracleDiscriminatorBytes, getInitializeOracleInstruction, getInitializeOracleInstructionAsync, getInitializeOracleInstructionDataCodec, getInitializeOracleInstructionDataDecoder, getInitializeOracleInstructionDataEncoder, getInitializePoolDiscriminatorBytes, getInitializePoolInstruction, getInitializePoolInstructionAsync, getInitializePoolInstructionDataCodec, getInitializePoolInstructionDataDecoder, getInitializePoolInstructionDataEncoder, getInitializeSpotPoolDiscriminatorBytes, getInitializeSpotPoolInstruction, getInitializeSpotPoolInstructionAsync, getInitializeSpotPoolInstructionDataCodec, getInitializeSpotPoolInstructionDataDecoder, getInitializeSpotPoolInstructionDataEncoder, getK, getOracleAddressFromPool, getOracleAge, getOracleBufferStats, getOracleConsultDiscriminatorBytes, getOracleConsultInstruction, getOracleConsultInstructionAsync, getOracleConsultInstructionDataCodec, getOracleConsultInstructionDataDecoder, getOracleConsultInstructionDataEncoder, getOracleDeviation, getOracleForPool, getOracleSpotPrices, getOracleUpdateDiscriminatorBytes, getOracleUpdateInstruction, getOracleUpdateInstructionAsync, getOracleUpdateInstructionDataCodec, getOracleUpdateInstructionDataDecoder, getOracleUpdateInstructionDataEncoder, getPauseDiscriminatorBytes, getPauseInstruction, getPauseInstructionDataCodec, getPauseInstructionDataDecoder, getPauseInstructionDataEncoder, getPendingFees, getPoolAddressFromMints, getPoolByMints, getPositionAddressFromParams, getPositionValue, getPreviewSwapExactInDiscriminatorBytes, getPreviewSwapExactInInstruction, getPreviewSwapExactInInstructionDataCodec, getPreviewSwapExactInInstructionDataDecoder, getPreviewSwapExactInInstructionDataEncoder, getRedeemProtocolSharesDiscriminatorBytes, getRedeemProtocolSharesInstruction, getRedeemProtocolSharesInstructionAsync, getRedeemProtocolSharesInstructionDataCodec, getRedeemProtocolSharesInstructionDataDecoder, getRedeemProtocolSharesInstructionDataEncoder, getRemoveLiquidityDiscriminatorBytes, getRemoveLiquidityInstruction, getRemoveLiquidityInstructionAsync, getRemoveLiquidityInstructionDataCodec, getRemoveLiquidityInstructionDataDecoder, getRemoveLiquidityInstructionDataEncoder, getRemoveLiquidityQuote, getSetFeesDiscriminatorBytes, getSetFeesInstruction, getSetFeesInstructionDataCodec, getSetFeesInstructionDataDecoder, getSetFeesInstructionDataEncoder, getSetHookDiscriminatorBytes, getSetHookInstruction, getSetHookInstructionDataCodec, getSetHookInstructionDataDecoder, getSetHookInstructionDataEncoder, getSpotPrice0, getSpotPrice1, getSwapExactInDiscriminatorBytes, getSwapExactInInstruction, getSwapExactInInstructionAsync, getSwapExactInInstructionDataCodec, getSwapExactInInstructionDataDecoder, getSwapExactInInstructionDataEncoder, getSwapQuote, getSwapQuoteExactOut, getTransferAdminDiscriminatorBytes, getTransferAdminInstruction, getTransferAdminInstructionDataCodec, getTransferAdminInstructionDataDecoder, getTransferAdminInstructionDataEncoder, getTvl, getUnpauseDiscriminatorBytes, getUnpauseInstruction, getUnpauseInstructionDataCodec, getUnpauseInstructionDataDecoder, getUnpauseInstructionDataEncoder, getUpdateConfigDiscriminatorBytes, getUpdateConfigInstruction, getUpdateConfigInstructionDataCodec, getUpdateConfigInstructionDataDecoder, getUpdateConfigInstructionDataEncoder, getWithdrawVaultExcessDiscriminatorBytes, getWithdrawVaultExcessInstruction, getWithdrawVaultExcessInstructionAsync, getWithdrawVaultExcessInstructionDataCodec, getWithdrawVaultExcessInstructionDataDecoder, getWithdrawVaultExcessInstructionDataEncoder, initializeConfigArgsCodec, initializeOracleArgsCodec, initializePoolArgsCodec, isOracleStale, isTransactionSigner, isqrt, maxBigInt, minBigInt, normalizeProgramAccountsResponse, numberToQ64, observationCodec, oracleConsultArgsCodec, oracleStateDataCodec, parseAddLiquidityInstruction, parseClosePositionInstruction, parseCollectFeesInstruction, parseCollectProtocolFeesInstruction, parseCreatePositionInstruction, parseInitializeConfigInstruction, parseInitializeOracleInstruction, parseInitializePoolInstruction, parseInitializeSpotPoolInstruction, parseOracleConsultInstruction, parseOracleUpdateInstruction, parsePauseInstruction, parsePreviewSwapExactInInstruction, parseRedeemProtocolSharesInstruction, parseRemoveLiquidityInstruction, parseSetFeesInstruction, parseSetHookInstruction, parseSwapExactInInstruction, parseTransferAdminInstruction, parseUnpauseInstruction, parseUpdateConfigInstruction, parseWithdrawVaultExcessInstruction, poolDataCodec, poolExists, positionDataCodec, q64Div, q64Mul, q64ToNumber, ratioToNumber, removeLiquidityArgsCodec, setFeesArgsCodec, setHookArgsCodec, sortPoolsByReserves, sortPositionsByShares, swapExactInArgsCodec, transferAdminArgsCodec, warnAccountDecodeFailure };
4168
+ //# sourceMappingURL=chunk-PSLY7M7C.js.map
4169
+ //# sourceMappingURL=chunk-PSLY7M7C.js.map