Skip to content

Commit c7a4f0b

Browse files
committed
sdk: add new admin client fn
1 parent ffa2138 commit c7a4f0b

File tree

1 file changed

+141
-76
lines changed

1 file changed

+141
-76
lines changed

sdk/src/adminClient.ts

Lines changed: 141 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
ContractTier,
1515
AssetTier,
1616
SpotFulfillmentConfigStatus,
17+
IfRebalanceConfigParams,
1718
} from './types';
1819
import { DEFAULT_MARKET_NAME, encodeName } from './userName';
1920
import { BN } from '@coral-xyz/anchor';
@@ -37,6 +38,7 @@ import {
3738
getProtectedMakerModeConfigPublicKey,
3839
getFuelOverflowAccountPublicKey,
3940
getTokenProgramForSpotMarket,
41+
getIfRebalanceConfigPublicKey,
4042
} from './addresses/pda';
4143
import { squareRootBN } from './math/utils';
4244
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
@@ -3401,6 +3403,86 @@ export class AdminClient extends DriftClient {
34013403
);
34023404
}
34033405

3406+
public async updatePerpMarketTakerSpeedBumpOverride(
3407+
perpMarketIndex: number,
3408+
takerSpeedBumpOverride: number
3409+
): Promise<TransactionSignature> {
3410+
const updatePerpMarketTakerSpeedBumpOverrideIx =
3411+
await this.getUpdatePerpMarketTakerSpeedBumpOverrideIx(
3412+
perpMarketIndex,
3413+
takerSpeedBumpOverride
3414+
);
3415+
3416+
const tx = await this.buildTransaction(
3417+
updatePerpMarketTakerSpeedBumpOverrideIx
3418+
);
3419+
3420+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
3421+
3422+
return txSig;
3423+
}
3424+
3425+
public async getUpdatePerpMarketTakerSpeedBumpOverrideIx(
3426+
perpMarketIndex: number,
3427+
takerSpeedBumpOverride: number
3428+
): Promise<TransactionInstruction> {
3429+
return await this.program.instruction.updatePerpMarketTakerSpeedBumpOverride(
3430+
takerSpeedBumpOverride,
3431+
{
3432+
accounts: {
3433+
admin: this.isSubscribed
3434+
? this.getStateAccount().admin
3435+
: this.wallet.publicKey,
3436+
state: await this.getStatePublicKey(),
3437+
perpMarket: await getPerpMarketPublicKey(
3438+
this.program.programId,
3439+
perpMarketIndex
3440+
),
3441+
},
3442+
}
3443+
);
3444+
}
3445+
3446+
public async updatePerpMarketAmmSpreadAdjustment(
3447+
perpMarketIndex: number,
3448+
ammSpreadAdjustment: number
3449+
): Promise<TransactionSignature> {
3450+
const updatePerpMarketAmmSpreadAdjustmentIx =
3451+
await this.getUpdatePerpMarketAmmSpreadAdjustmentIx(
3452+
perpMarketIndex,
3453+
ammSpreadAdjustment
3454+
);
3455+
3456+
const tx = await this.buildTransaction(
3457+
updatePerpMarketAmmSpreadAdjustmentIx
3458+
);
3459+
3460+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
3461+
3462+
return txSig;
3463+
}
3464+
3465+
public async getUpdatePerpMarketAmmSpreadAdjustmentIx(
3466+
perpMarketIndex: number,
3467+
ammSpreadAdjustment: number
3468+
): Promise<TransactionInstruction> {
3469+
return await this.program.instruction.updatePerpMarketAmmSpreadAdjustment(
3470+
ammSpreadAdjustment,
3471+
{
3472+
accounts: {
3473+
admin: this.useHotWalletAdmin
3474+
? this.wallet.publicKey
3475+
: this.getStateAccount().admin,
3476+
state: await this.getStatePublicKey(),
3477+
perpMarket: await getPerpMarketPublicKey(
3478+
this.program.programId,
3479+
perpMarketIndex
3480+
),
3481+
},
3482+
}
3483+
);
3484+
}
3485+
34043486
public async updateSpotMarketFeeAdjustment(
34053487
perpMarketIndex: number,
34063488
feeAdjustment: number
@@ -3859,34 +3941,39 @@ export class AdminClient extends DriftClient {
38593941
);
38603942
}
38613943

3862-
public async updatePerpMarketTakerSpeedBumpOverride(
3944+
public async updatePerpMarketProtectedMakerParams(
38633945
perpMarketIndex: number,
3864-
takerSpeedBumpOverride: number
3946+
protectedMakerLimitPriceDivisor?: number,
3947+
protectedMakerDynamicDivisor?: number
38653948
): Promise<TransactionSignature> {
3866-
const updatePerpMarketTakerSpeedBumpOverrideIx =
3867-
await this.getUpdatePerpMarketTakerSpeedBumpOverrideIx(
3949+
const updatePerpMarketProtectedMakerParamsIx =
3950+
await this.getUpdatePerpMarketProtectedMakerParamsIx(
38683951
perpMarketIndex,
3869-
takerSpeedBumpOverride
3952+
protectedMakerLimitPriceDivisor || null,
3953+
protectedMakerDynamicDivisor || null
38703954
);
3955+
38713956
const tx = await this.buildTransaction(
3872-
updatePerpMarketTakerSpeedBumpOverrideIx
3957+
updatePerpMarketProtectedMakerParamsIx
38733958
);
38743959
const { txSig } = await this.sendTransaction(tx, [], this.opts);
38753960

38763961
return txSig;
38773962
}
38783963

3879-
public async getUpdatePerpMarketTakerSpeedBumpOverrideIx(
3964+
public async getUpdatePerpMarketProtectedMakerParamsIx(
38803965
perpMarketIndex: number,
3881-
takerSpeedBumpOverride: number
3966+
protectedMakerLimitPriceDivisor?: number,
3967+
protectedMakerDynamicDivisor?: number
38823968
): Promise<TransactionInstruction> {
38833969
const perpMarketPublicKey = await getPerpMarketPublicKey(
38843970
this.program.programId,
38853971
perpMarketIndex
38863972
);
38873973

3888-
return await this.program.instruction.updatePerpMarketTakerSpeedBumpOverride(
3889-
takerSpeedBumpOverride,
3974+
return await this.program.instruction.updatePerpMarketProtectedMakerParams(
3975+
protectedMakerLimitPriceDivisor || null,
3976+
protectedMakerDynamicDivisor || null,
38903977
{
38913978
accounts: {
38923979
admin: this.isSubscribed
@@ -3899,89 +3986,67 @@ export class AdminClient extends DriftClient {
38993986
);
39003987
}
39013988

3902-
public async updatePerpMarketAmmSpreadAdjustment(
3903-
perpMarketIndex: number,
3904-
ammSpreadAdjustment: number
3989+
public async initializeIfRebalanceConfig(
3990+
params: IfRebalanceConfigParams
39053991
): Promise<TransactionSignature> {
3906-
const updatePerpMarketAmmSpreadAdjustmentIx =
3907-
await this.getUpdatePerpMarketAmmSpreadAdjustmentIx(
3908-
perpMarketIndex,
3909-
ammSpreadAdjustment
3910-
);
3911-
const tx = await this.buildTransaction(
3912-
updatePerpMarketAmmSpreadAdjustmentIx
3913-
);
3992+
const initializeIfRebalanceConfigIx =
3993+
await this.getInitializeIfRebalanceConfigIx(params);
3994+
3995+
const tx = await this.buildTransaction(initializeIfRebalanceConfigIx);
39143996
const { txSig } = await this.sendTransaction(tx, [], this.opts);
39153997

39163998
return txSig;
39173999
}
39184000

3919-
public async getUpdatePerpMarketAmmSpreadAdjustmentIx(
3920-
perpMarketIndex: number,
3921-
ammSpreadAdjustment: number
4001+
public async getInitializeIfRebalanceConfigIx(
4002+
params: IfRebalanceConfigParams
39224003
): Promise<TransactionInstruction> {
3923-
const perpMarketPublicKey = await getPerpMarketPublicKey(
3924-
this.program.programId,
3925-
perpMarketIndex
3926-
);
3927-
3928-
return await this.program.instruction.updatePerpMarketAmmSpreadAdjustment(
3929-
ammSpreadAdjustment,
3930-
{
3931-
accounts: {
3932-
admin: this.isSubscribed
3933-
? this.getStateAccount().admin
3934-
: this.wallet.publicKey,
3935-
state: await this.getStatePublicKey(),
3936-
perpMarket: perpMarketPublicKey,
3937-
},
3938-
}
3939-
);
4004+
return await this.program.instruction.initializeIfRebalanceConfig(params, {
4005+
accounts: {
4006+
admin: this.isSubscribed
4007+
? this.getStateAccount().admin
4008+
: this.wallet.publicKey,
4009+
state: await this.getStatePublicKey(),
4010+
ifRebalanceConfig: await getIfRebalanceConfigPublicKey(
4011+
this.program.programId,
4012+
params.inMarketIndex,
4013+
params.outMarketIndex
4014+
),
4015+
rent: SYSVAR_RENT_PUBKEY,
4016+
systemProgram: anchor.web3.SystemProgram.programId,
4017+
},
4018+
});
39404019
}
39414020

3942-
public async updatePerpMarketProtectedMakerParams(
3943-
perpMarketIndex: number,
3944-
protectedMakerLimitPriceDivisor?: number,
3945-
protectedMakerDynamicDivisor?: number
4021+
public async updateIfRebalanceConfig(
4022+
params: IfRebalanceConfigParams
39464023
): Promise<TransactionSignature> {
3947-
const updatePerpMarketProtectedMakerParamsIx =
3948-
await this.getUpdatePerpMarketProtectedMakerParamsIx(
3949-
perpMarketIndex,
3950-
protectedMakerLimitPriceDivisor || null,
3951-
protectedMakerDynamicDivisor || null
3952-
);
3953-
3954-
const tx = await this.buildTransaction(
3955-
updatePerpMarketProtectedMakerParamsIx
4024+
const updateIfRebalanceConfigIx = await this.getUpdateIfRebalanceConfigIx(
4025+
params
39564026
);
4027+
4028+
const tx = await this.buildTransaction(updateIfRebalanceConfigIx);
39574029
const { txSig } = await this.sendTransaction(tx, [], this.opts);
39584030

39594031
return txSig;
39604032
}
39614033

3962-
public async getUpdatePerpMarketProtectedMakerParamsIx(
3963-
perpMarketIndex: number,
3964-
protectedMakerLimitPriceDivisor?: number,
3965-
protectedMakerDynamicDivisor?: number
4034+
public async getUpdateIfRebalanceConfigIx(
4035+
params: IfRebalanceConfigParams
39664036
): Promise<TransactionInstruction> {
3967-
const perpMarketPublicKey = await getPerpMarketPublicKey(
3968-
this.program.programId,
3969-
perpMarketIndex
3970-
);
3971-
3972-
return await this.program.instruction.updatePerpMarketProtectedMakerParams(
3973-
protectedMakerLimitPriceDivisor || null,
3974-
protectedMakerDynamicDivisor || null,
3975-
{
3976-
accounts: {
3977-
admin: this.isSubscribed
3978-
? this.getStateAccount().admin
3979-
: this.wallet.publicKey,
3980-
state: await this.getStatePublicKey(),
3981-
perpMarket: perpMarketPublicKey,
3982-
},
3983-
}
3984-
);
4037+
return await this.program.instruction.updateIfRebalanceConfig(params, {
4038+
accounts: {
4039+
admin: this.isSubscribed
4040+
? this.getStateAccount().admin
4041+
: this.wallet.publicKey,
4042+
state: await this.getStatePublicKey(),
4043+
ifRebalanceConfig: await getIfRebalanceConfigPublicKey(
4044+
this.program.programId,
4045+
params.inMarketIndex,
4046+
params.outMarketIndex
4047+
),
4048+
},
4049+
});
39854050
}
39864051

39874052
public async initUserFuel(

0 commit comments

Comments
 (0)