Skip to content

Commit

Permalink
sdk: add methods to init pmm
Browse files Browse the repository at this point in the history
  • Loading branch information
crispheaney committed Dec 16, 2024
1 parent dc58e66 commit 38bf5fb
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
13 changes: 13 additions & 0 deletions sdk/src/addresses/pda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,16 @@ export function getHighLeverageModeConfigPublicKey(
programId
)[0];
}

export function getProtectedMakerModeConfigPublicKey(
programId: PublicKey
): PublicKey {
return PublicKey.findProgramAddressSync(
[
Buffer.from(
anchor.utils.bytes.utf8.encode('protected_maker_mode_config')
),
],
programId
)[0];
}
72 changes: 72 additions & 0 deletions sdk/src/adminClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
getUserStatsAccountPublicKey,
getHighLeverageModeConfigPublicKey,
getPythLazerOraclePublicKey,
getProtectedMakerModeConfigPublicKey,
} from './addresses/pda';
import { squareRootBN } from './math/utils';
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
Expand Down Expand Up @@ -4027,4 +4028,75 @@ export class AdminClient extends DriftClient {
}
);
}

public async initializeProtectedMakerModeConfig(
maxUsers: number
): Promise<TransactionSignature> {
const initializeProtectedMakerModeConfigIx =
await this.getInitializeProtectedMakerModeConfigIx(maxUsers);

const tx = await this.buildTransaction(
initializeProtectedMakerModeConfigIx
);

const { txSig } = await this.sendTransaction(tx, [], this.opts);

return txSig;
}

public async getInitializeProtectedMakerModeConfigIx(
maxUsers: number
): Promise<TransactionInstruction> {
return await this.program.instruction.initializeProtectedMakerModeConfig(
maxUsers,
{
accounts: {
admin: this.isSubscribed
? this.getStateAccount().admin
: this.wallet.publicKey,
state: await this.getStatePublicKey(),
rent: SYSVAR_RENT_PUBKEY,
systemProgram: anchor.web3.SystemProgram.programId,
protectedMakerModeConfig: getProtectedMakerModeConfigPublicKey(
this.program.programId
),
},
}
);
}

public async updateProtectedMakerModeConfig(
maxUsers: number,
reduceOnly: boolean
): Promise<TransactionSignature> {
const updateProtectedMakerModeConfigIx =
await this.getUpdateProtectedMakerModeConfigIx(maxUsers, reduceOnly);

const tx = await this.buildTransaction(updateProtectedMakerModeConfigIx);

const { txSig } = await this.sendTransaction(tx, [], this.opts);

return txSig;
}

public async getUpdateProtectedMakerModeConfigIx(
maxUsers: number,
reduceOnly: boolean
): Promise<TransactionInstruction> {
return await this.program.instruction.updateProtectedMakerModeConfig(
maxUsers,
reduceOnly,
{
accounts: {
admin: this.isSubscribed
? this.getStateAccount().admin
: this.wallet.publicKey,
state: await this.getStatePublicKey(),
protectedMakerModeConfig: getProtectedMakerModeConfigPublicKey(
this.program.programId
),
},
}
);
}
}
1 change: 0 additions & 1 deletion sdk/src/driftClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,6 @@ export class DriftClient {

const subscriptionPromises: Promise<any>[] = [this.userStats.subscribe()];


let success = true;

if (this.isSubscribed) {
Expand Down

0 comments on commit 38bf5fb

Please sign in to comment.