Skip to content

Commit fa47f31

Browse files
moosecat2crispheaney
authored andcommitted
Nour/move ixs around (#1766)
* move around ixs * remove message
1 parent f493187 commit fa47f31

File tree

4 files changed

+112
-110
lines changed

4 files changed

+112
-110
lines changed

programs/drift/src/instructions/admin.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4846,7 +4846,6 @@ pub fn handle_update_if_rebalance_config(
48464846
pub fn handle_update_mm_oracle_native(accounts: &[AccountInfo], data: &[u8]) -> Result<()> {
48474847
// Verify this ix is allowed
48484848
let state = &accounts[3].data.borrow();
4849-
msg!("state bytes: {:?}", &state[981..988]);
48504849
assert!(state[982] & 1 == 0, "ix disabled by admin state");
48514850

48524851
let signer_account = &accounts[1];

sdk/src/adminClient.ts

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
PublicKey,
33
SystemProgram,
4-
SYSVAR_CLOCK_PUBKEY,
54
SYSVAR_RENT_PUBKEY,
65
TransactionInstruction,
76
TransactionSignature,
@@ -58,7 +57,6 @@ import { PROGRAM_ID as PHOENIX_PROGRAM_ID } from '@ellipsis-labs/phoenix-sdk';
5857
import { DRIFT_ORACLE_RECEIVER_ID } from './config';
5958
import { getFeedIdUint8Array } from './util/pythOracleUtils';
6059
import { FUEL_RESET_LOG_ACCOUNT } from './constants/txConstants';
61-
import { createNativeInstructionDiscriminatorBuffer } from './tx/utils';
6260

6361
const OPENBOOK_PROGRAM_ID = new PublicKey(
6462
'opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb'
@@ -4554,112 +4552,6 @@ export class AdminClient extends DriftClient {
45544552
});
45554553
}
45564554

4557-
public async updateMmOracleNative(
4558-
marketIndex: number,
4559-
oraclePrice: BN,
4560-
oracleSequenceId: BN
4561-
): Promise<TransactionSignature> {
4562-
const updateMmOracleIx = await this.getUpdateMmOracleNativeIx(
4563-
marketIndex,
4564-
oraclePrice,
4565-
oracleSequenceId
4566-
);
4567-
4568-
const tx = await this.buildTransaction(updateMmOracleIx, {
4569-
computeUnits: 5000,
4570-
computeUnitsPrice: 0,
4571-
});
4572-
const { txSig } = await this.sendTransaction(tx, [], this.opts);
4573-
4574-
return txSig;
4575-
}
4576-
4577-
public async getUpdateMmOracleNativeIx(
4578-
marketIndex: number,
4579-
oraclePrice: BN,
4580-
oracleSequenceId: BN
4581-
): Promise<TransactionInstruction> {
4582-
const discriminatorBuffer = createNativeInstructionDiscriminatorBuffer(0);
4583-
const data = Buffer.alloc(discriminatorBuffer.length + 16);
4584-
data.set(discriminatorBuffer, 0);
4585-
data.set(oraclePrice.toArrayLike(Buffer, 'le', 8), 5); // next 8 bytes
4586-
data.set(oracleSequenceId.toArrayLike(Buffer, 'le', 8), 13); // next 8 bytes
4587-
4588-
// Build the instruction manually
4589-
return new TransactionInstruction({
4590-
programId: this.program.programId,
4591-
keys: [
4592-
{
4593-
pubkey: this.getPerpMarketAccount(marketIndex).pubkey,
4594-
isWritable: true,
4595-
isSigner: false,
4596-
},
4597-
{
4598-
pubkey: this.wallet.publicKey,
4599-
isWritable: false,
4600-
isSigner: true,
4601-
},
4602-
{
4603-
pubkey: SYSVAR_CLOCK_PUBKEY,
4604-
isWritable: false,
4605-
isSigner: false,
4606-
},
4607-
{
4608-
pubkey: await this.getStatePublicKey(),
4609-
isWritable: false,
4610-
isSigner: false,
4611-
},
4612-
],
4613-
data,
4614-
});
4615-
}
4616-
4617-
public async updateAmmSpreadAdjustmentNative(
4618-
marketIndex: number,
4619-
ammSpreadAdjustment: number
4620-
): Promise<TransactionSignature> {
4621-
const updateMmOracleIx = await this.getUpdateAmmSpreadAdjustmentNativeIx(
4622-
marketIndex,
4623-
ammSpreadAdjustment
4624-
);
4625-
4626-
const tx = await this.buildTransaction(updateMmOracleIx, {
4627-
computeUnits: 1000,
4628-
computeUnitsPrice: 0,
4629-
});
4630-
const { txSig } = await this.sendTransaction(tx, [], this.opts);
4631-
4632-
return txSig;
4633-
}
4634-
4635-
public getUpdateAmmSpreadAdjustmentNativeIx(
4636-
marketIndex: number,
4637-
ammSpreadAdjustment: number // i8
4638-
): TransactionInstruction {
4639-
const discriminatorBuffer = createNativeInstructionDiscriminatorBuffer(1);
4640-
const data = Buffer.alloc(discriminatorBuffer.length + 4);
4641-
data.set(discriminatorBuffer, 0);
4642-
data.writeInt8(ammSpreadAdjustment, 5); // next byte
4643-
4644-
// Build the instruction manually
4645-
return new TransactionInstruction({
4646-
programId: this.program.programId,
4647-
keys: [
4648-
{
4649-
pubkey: this.getPerpMarketAccount(marketIndex).pubkey,
4650-
isWritable: true,
4651-
isSigner: false,
4652-
},
4653-
{
4654-
pubkey: this.wallet.publicKey,
4655-
isWritable: false,
4656-
isSigner: true,
4657-
},
4658-
],
4659-
data,
4660-
});
4661-
}
4662-
46634555
public async updateDisableBitFlagsMMOracle(
46644556
disable: boolean
46654557
): Promise<TransactionSignature> {

sdk/src/driftClient.ts

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import {
7878
PublicKey,
7979
Signer,
8080
SystemProgram,
81+
SYSVAR_CLOCK_PUBKEY,
8182
SYSVAR_INSTRUCTIONS_PUBKEY,
8283
Transaction,
8384
TransactionInstruction,
@@ -177,7 +178,10 @@ import { WormholeCoreBridgeSolana } from '@pythnetwork/pyth-solana-receiver/lib/
177178
import { PythSolanaReceiver } from '@pythnetwork/pyth-solana-receiver/lib/idl/pyth_solana_receiver';
178179
import { getFeedIdUint8Array, trimFeedId } from './util/pythOracleUtils';
179180
import { createMinimalEd25519VerifyIx } from './util/ed25519Utils';
180-
import { isVersionedTransaction } from './tx/utils';
181+
import {
182+
createNativeInstructionDiscriminatorBuffer,
183+
isVersionedTransaction,
184+
} from './tx/utils';
181185
import pythSolanaReceiverIdl from './idl/pyth_solana_receiver.json';
182186
import { asV0Tx, PullFeed, AnchorUtils } from '@switchboard-xyz/on-demand';
183187
import { gprcDriftClientAccountSubscriber } from './accounts/grpcDriftClientAccountSubscriber';
@@ -9917,6 +9921,112 @@ export class DriftClient {
99179921
return txSig;
99189922
}
99199923

9924+
public async updateMmOracleNative(
9925+
marketIndex: number,
9926+
oraclePrice: BN,
9927+
oracleSequenceId: BN
9928+
): Promise<TransactionSignature> {
9929+
const updateMmOracleIx = await this.getUpdateMmOracleNativeIx(
9930+
marketIndex,
9931+
oraclePrice,
9932+
oracleSequenceId
9933+
);
9934+
9935+
const tx = await this.buildTransaction(updateMmOracleIx, {
9936+
computeUnits: 5000,
9937+
computeUnitsPrice: 0,
9938+
});
9939+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
9940+
9941+
return txSig;
9942+
}
9943+
9944+
public async getUpdateMmOracleNativeIx(
9945+
marketIndex: number,
9946+
oraclePrice: BN,
9947+
oracleSequenceId: BN
9948+
): Promise<TransactionInstruction> {
9949+
const discriminatorBuffer = createNativeInstructionDiscriminatorBuffer(0);
9950+
const data = Buffer.alloc(discriminatorBuffer.length + 16);
9951+
data.set(discriminatorBuffer, 0);
9952+
data.set(oraclePrice.toArrayLike(Buffer, 'le', 8), 5); // next 8 bytes
9953+
data.set(oracleSequenceId.toArrayLike(Buffer, 'le', 8), 13); // next 8 bytes
9954+
9955+
// Build the instruction manually
9956+
return new TransactionInstruction({
9957+
programId: this.program.programId,
9958+
keys: [
9959+
{
9960+
pubkey: this.getPerpMarketAccount(marketIndex).pubkey,
9961+
isWritable: true,
9962+
isSigner: false,
9963+
},
9964+
{
9965+
pubkey: this.wallet.publicKey,
9966+
isWritable: false,
9967+
isSigner: true,
9968+
},
9969+
{
9970+
pubkey: SYSVAR_CLOCK_PUBKEY,
9971+
isWritable: false,
9972+
isSigner: false,
9973+
},
9974+
{
9975+
pubkey: await this.getStatePublicKey(),
9976+
isWritable: false,
9977+
isSigner: false,
9978+
},
9979+
],
9980+
data,
9981+
});
9982+
}
9983+
9984+
public async updateAmmSpreadAdjustmentNative(
9985+
marketIndex: number,
9986+
ammSpreadAdjustment: number
9987+
): Promise<TransactionSignature> {
9988+
const updateMmOracleIx = await this.getUpdateAmmSpreadAdjustmentNativeIx(
9989+
marketIndex,
9990+
ammSpreadAdjustment
9991+
);
9992+
9993+
const tx = await this.buildTransaction(updateMmOracleIx, {
9994+
computeUnits: 1000,
9995+
computeUnitsPrice: 0,
9996+
});
9997+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
9998+
9999+
return txSig;
10000+
}
10001+
10002+
public getUpdateAmmSpreadAdjustmentNativeIx(
10003+
marketIndex: number,
10004+
ammSpreadAdjustment: number // i8
10005+
): TransactionInstruction {
10006+
const discriminatorBuffer = createNativeInstructionDiscriminatorBuffer(1);
10007+
const data = Buffer.alloc(discriminatorBuffer.length + 4);
10008+
data.set(discriminatorBuffer, 0);
10009+
data.writeInt8(ammSpreadAdjustment, 5); // next byte
10010+
10011+
// Build the instruction manually
10012+
return new TransactionInstruction({
10013+
programId: this.program.programId,
10014+
keys: [
10015+
{
10016+
pubkey: this.getPerpMarketAccount(marketIndex).pubkey,
10017+
isWritable: true,
10018+
isSigner: false,
10019+
},
10020+
{
10021+
pubkey: this.wallet.publicKey,
10022+
isWritable: false,
10023+
isSigner: true,
10024+
},
10025+
],
10026+
data,
10027+
});
10028+
}
10029+
992010030
private handleSignedTransaction(signedTxs: SignedTxData[]) {
992110031
if (this.enableMetricsEvents && this.metricsEventEmitter) {
992210032
this.metricsEventEmitter.emit('txSigned', signedTxs);

sdk/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export * from './oracles/pythPullClient';
9090
export * from './oracles/pythLazerClient';
9191
export * from './oracles/switchboardOnDemandClient';
9292
export * from './oracles/oracleId';
93+
export * from './oracles/utils';
9394
export * from './swift/swiftOrderSubscriber';
9495
export * from './swift/signedMsgUserAccountSubscriber';
9596
export * from './swift/grpcSignedMsgUserAccountSubscriber';

0 commit comments

Comments
 (0)