Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
codewithgun committed Jan 3, 2025
1 parent 0be4b86 commit 94e8345
Show file tree
Hide file tree
Showing 7 changed files with 1,675 additions and 101 deletions.
Binary file modified artifacts/lb_clmm.so
Binary file not shown.
11 changes: 11 additions & 0 deletions ts-client/src/dlmm/helpers/derive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,14 @@ export function deriveEventAuthority(programId: PublicKey) {
programId
);
}

export function deriveRewardVault(
lbPair: PublicKey,
rewardIndex: BN,
programId: PublicKey
) {
return PublicKey.findProgramAddressSync(
[lbPair.toBuffer(), rewardIndex.toArrayLike(Buffer, "le", 8)],
programId
);
}
19 changes: 11 additions & 8 deletions ts-client/src/dlmm/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BN, EventParser } from "@coral-xyz/anchor";
import {
ASSOCIATED_TOKEN_PROGRAM_ID,
NATIVE_MINT,
TOKEN_PROGRAM_ID,
TokenAccountNotFoundError,
Expand Down Expand Up @@ -37,11 +38,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 @@ -93,17 +90,21 @@ export const getOrCreateATAInstruction = async (
connection: Connection,
tokenMint: PublicKey,
owner: PublicKey,
programId?: PublicKey,
payer: PublicKey = owner,
allowOwnerOffCurve = true
): Promise<GetOrCreateATAResponse> => {
programId = programId ?? TOKEN_PROGRAM_ID;
const toAccount = getAssociatedTokenAddressSync(
tokenMint,
owner,
allowOwnerOffCurve
allowOwnerOffCurve,
programId,
ASSOCIATED_TOKEN_PROGRAM_ID
);

try {
await getAccount(connection, toAccount);
await getAccount(connection, toAccount, connection.commitment, programId);

return { ataPubKey: toAccount, ix: undefined };
} catch (e) {
Expand All @@ -115,7 +116,9 @@ export const getOrCreateATAInstruction = async (
payer,
toAccount,
owner,
tokenMint
tokenMint,
programId,
ASSOCIATED_TOKEN_PROGRAM_ID
);

return { ataPubKey: toAccount, ix };
Expand Down
Loading

0 comments on commit 94e8345

Please sign in to comment.