@meteora-ag/cp-amm-sdk 1.4.4 → 1.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +37 -1
- package/dist/index.d.ts +37 -1
- package/dist/index.js +83 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +82 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -7761,6 +7761,8 @@ var DEAD_LIQUIDITY = new BN(100).shln(SCALE_OFFSET);
|
|
|
7761
7761
|
var NUM_REWARDS = 2;
|
|
7762
7762
|
var MIN_REWARD_DURATION = 86400;
|
|
7763
7763
|
var MAX_REWARD_DURATION = 31536e3;
|
|
7764
|
+
var POOL_TOKEN_A_MINT_OFFSET = 168;
|
|
7765
|
+
var POOL_TOKEN_B_MINT_OFFSET = 200;
|
|
7764
7766
|
|
|
7765
7767
|
// src/pda.ts
|
|
7766
7768
|
function getFirstKey(key1, key2) {
|
|
@@ -12061,11 +12063,44 @@ var CpAmm = class {
|
|
|
12061
12063
|
*/
|
|
12062
12064
|
fetchPoolStatesByTokenAMint(tokenAMint) {
|
|
12063
12065
|
return __async(this, null, function* () {
|
|
12064
|
-
const filters = offsetBasedFilter(tokenAMint,
|
|
12066
|
+
const filters = offsetBasedFilter(tokenAMint, POOL_TOKEN_A_MINT_OFFSET);
|
|
12065
12067
|
const pools = yield this._program.account.pool.all(filters);
|
|
12066
12068
|
return pools;
|
|
12067
12069
|
});
|
|
12068
12070
|
}
|
|
12071
|
+
/**
|
|
12072
|
+
* Fetches all Pool states by tokenBMint.
|
|
12073
|
+
* @param tokenBMint - Public key of the tokenB mint.
|
|
12074
|
+
* @returns Array of matched pool accounts and their state.
|
|
12075
|
+
*/
|
|
12076
|
+
fetchPoolStatesByTokenBMint(tokenBMint) {
|
|
12077
|
+
return __async(this, null, function* () {
|
|
12078
|
+
const filters = offsetBasedFilter(tokenBMint, POOL_TOKEN_B_MINT_OFFSET);
|
|
12079
|
+
const pools = yield this._program.account.pool.all(filters);
|
|
12080
|
+
return pools;
|
|
12081
|
+
});
|
|
12082
|
+
}
|
|
12083
|
+
/**
|
|
12084
|
+
* Fetches all Pool states that contain the given mint on either side of the pair
|
|
12085
|
+
* (tokenAMint or tokenBMint).
|
|
12086
|
+
* @param tokenMint - Public key of the token mint.
|
|
12087
|
+
* @returns Array of matched pool accounts and their state.
|
|
12088
|
+
*/
|
|
12089
|
+
fetchPoolStatesByTokenMint(tokenMint) {
|
|
12090
|
+
return __async(this, null, function* () {
|
|
12091
|
+
const [poolsByTokenA, poolsByTokenB] = yield Promise.all([
|
|
12092
|
+
this.fetchPoolStatesByTokenAMint(tokenMint),
|
|
12093
|
+
this.fetchPoolStatesByTokenBMint(tokenMint)
|
|
12094
|
+
]);
|
|
12095
|
+
const seen = /* @__PURE__ */ new Set();
|
|
12096
|
+
return [...poolsByTokenA, ...poolsByTokenB].filter((pool) => {
|
|
12097
|
+
const key = pool.publicKey.toBase58();
|
|
12098
|
+
if (seen.has(key)) return false;
|
|
12099
|
+
seen.add(key);
|
|
12100
|
+
return true;
|
|
12101
|
+
});
|
|
12102
|
+
});
|
|
12103
|
+
}
|
|
12069
12104
|
fetchPoolFees(pool) {
|
|
12070
12105
|
return __async(this, null, function* () {
|
|
12071
12106
|
const poolState = yield this._program.account.pool.fetchNullable(pool);
|
|
@@ -12256,6 +12291,50 @@ var CpAmm = class {
|
|
|
12256
12291
|
return positionResult;
|
|
12257
12292
|
});
|
|
12258
12293
|
}
|
|
12294
|
+
/**
|
|
12295
|
+
* Gets all positions of a user in pools that contain the given token mint on either side of
|
|
12296
|
+
* the pair. Resolves the user's positions first and then filters by their pools' mints, so it
|
|
12297
|
+
* never scans the program's pool accounts.
|
|
12298
|
+
* @param user - Public key of the user.
|
|
12299
|
+
* @param tokenMint - Public key of the token mint.
|
|
12300
|
+
* @returns Array of user positions (sorted by liquidity, descending) with their pool and state.
|
|
12301
|
+
*/
|
|
12302
|
+
getPositionsByUserAndTokenMint(user, tokenMint) {
|
|
12303
|
+
return __async(this, null, function* () {
|
|
12304
|
+
const userPositions = yield this.getPositionsByUser(user);
|
|
12305
|
+
if (userPositions.length === 0) {
|
|
12306
|
+
return [];
|
|
12307
|
+
}
|
|
12308
|
+
const uniquePools = [];
|
|
12309
|
+
const seenPools = /* @__PURE__ */ new Set();
|
|
12310
|
+
for (const { positionState } of userPositions) {
|
|
12311
|
+
const poolKey = positionState.pool.toBase58();
|
|
12312
|
+
if (!seenPools.has(poolKey)) {
|
|
12313
|
+
seenPools.add(poolKey);
|
|
12314
|
+
uniquePools.push(positionState.pool);
|
|
12315
|
+
}
|
|
12316
|
+
}
|
|
12317
|
+
const poolStates = yield this._program.account.pool.fetchMultiple(uniquePools);
|
|
12318
|
+
const matchedPools = /* @__PURE__ */ new Map();
|
|
12319
|
+
uniquePools.forEach((pool, index) => {
|
|
12320
|
+
const poolState = poolStates[index];
|
|
12321
|
+
if (!poolState) return;
|
|
12322
|
+
if (poolState.tokenAMint.equals(tokenMint) || poolState.tokenBMint.equals(tokenMint)) {
|
|
12323
|
+
matchedPools.set(pool.toBase58(), poolState);
|
|
12324
|
+
}
|
|
12325
|
+
});
|
|
12326
|
+
return userPositions.map((userPosition) => {
|
|
12327
|
+
const poolState = matchedPools.get(
|
|
12328
|
+
userPosition.positionState.pool.toBase58()
|
|
12329
|
+
);
|
|
12330
|
+
if (!poolState) return null;
|
|
12331
|
+
return __spreadProps(__spreadValues({}, userPosition), {
|
|
12332
|
+
pool: userPosition.positionState.pool,
|
|
12333
|
+
poolState
|
|
12334
|
+
});
|
|
12335
|
+
}).filter(Boolean);
|
|
12336
|
+
});
|
|
12337
|
+
}
|
|
12259
12338
|
/**
|
|
12260
12339
|
* Retrieves all vesting accounts associated with a position.
|
|
12261
12340
|
* @param position - Public key of the position.
|
|
@@ -14562,6 +14641,8 @@ export {
|
|
|
14562
14641
|
MathOverflowError,
|
|
14563
14642
|
NUM_REWARDS,
|
|
14564
14643
|
ONE_Q64,
|
|
14644
|
+
POOL_TOKEN_A_MINT_OFFSET,
|
|
14645
|
+
POOL_TOKEN_B_MINT_OFFSET,
|
|
14565
14646
|
PoolStatus,
|
|
14566
14647
|
PositionDelegatePermission,
|
|
14567
14648
|
PriceRangeViolationError,
|