Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove unused dependency #150

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Security

## @meteora-ag/dlmm [1.3.9] - PR #150

### Removed

- Remove non-solana official libs and unused dependency

## @meteora-ag/dlmm [1.3.8] - PR #144

### Fixed

- Fix `getOrCreateATAInstruction` to use `createAssociatedTokenAccountIdempotentInstruction`
- Fix `getOrCreateATAInstruction` to use `createAssociatedTokenAccountIdempotentInstruction`

## @meteora-ag/dlmm [1.3.7] - PR #143

Expand All @@ -36,7 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Refactored; remove `position(V1)` interaction from SDK
- Throw error in `removeLiquidity` function if position doesn't have any liquidity
- Throw error in `removeLiquidity` function if position doesn't have any liquidity

### Fixed

Expand Down
6 changes: 2 additions & 4 deletions ts-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meteora-ag/dlmm",
"version": "1.3.8",
"version": "1.3.9",
"description": "",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down Expand Up @@ -35,14 +35,12 @@
"dependencies": {
"@coral-xyz/anchor": "^0.28.0",
"@coral-xyz/borsh": "^0.28.0",
"@solana-developers/helpers": "^2.5.6",
"@solana/buffer-layout": "^4.0.1",
"@solana/spl-token": "^0.4.6",
"@solana/web3.js": "^1.91.6",
"bn.js": "^5.2.1",
"decimal.js": "^10.4.2",
"express": "^4.19.2",
"gaussian": "^1.3.0"
"express": "^4.19.2"
},
"keywords": [],
"author": "McSam",
Expand Down
47 changes: 41 additions & 6 deletions ts-client/src/dlmm/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ import {
} from "@solana/spl-token";
import { SCALE_OFFSET } from "../constants";
import {
AddressLookupTableAccount,
ComputeBudgetProgram,
Connection,
PublicKey,
SystemProgram,
TransactionInstruction,
TransactionMessage,
VersionedTransaction,
} from "@solana/web3.js";
import { Bin, ClmmProgram, GetOrCreateATAResponse } from "../types";
import { Rounding, mulShr, shlDiv } from "./math";
import { getSimulationComputeUnits } from "@solana-developers/helpers";
import { MAX_CU_BUFFER, MIN_CU_BUFFER } from "./computeUnit";

export * from "./derive";
Expand All @@ -38,11 +40,7 @@ export function chunks<T>(array: T[], size: number): T[][] {
);
}

export function range<T>(
min: number,
max: number,
mapfn: (i: number) => T
) {
export function range<T>(min: number, max: number, mapfn: (i: number) => T) {
const length = max - min + 1;
return Array.from({ length }, (_, i) => mapfn(min + i));
}
Expand Down Expand Up @@ -209,6 +207,43 @@ export async function chunkedGetMultipleAccountInfos(
return accountInfos;
}

export const getSimulationComputeUnits = async (
connection: Connection,
instructions: Array<TransactionInstruction>,
payer: PublicKey,
lookupTables: Array<AddressLookupTableAccount> | []
): Promise<number | null> => {
const testInstructions = [
// Set an arbitrarily high number in simulation
// so we can be sure the transaction will succeed
// and get the real compute units used
ComputeBudgetProgram.setComputeUnitLimit({ units: 1_400_000 }),
...instructions,
];

const testTransaction = new VersionedTransaction(
new TransactionMessage({
instructions: testInstructions,
payerKey: payer,
// RecentBlockhash can by any public key during simulation
// since 'replaceRecentBlockhash' is set to 'true' below
recentBlockhash: PublicKey.default.toString(),
}).compileToV0Message(lookupTables)
);

const rpcResponse = await connection.simulateTransaction(testTransaction, {
replaceRecentBlockhash: true,
sigVerify: false,
});

if (rpcResponse?.value?.err) {
const logs = rpcResponse.value.logs?.join("\n • ") || "No logs available";
throw new Error(`Transaction simulation failed:\n •${logs}`);
}

return rpcResponse.value.unitsConsumed || null;
};

/**
* Gets the estimated compute unit usage with a buffer.
* @param connection A Solana connection object.
Expand Down
Loading
Loading