@drift-labs/sdk 2.71.0-beta.0 → 2.71.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/VERSION +1 -1
- package/lib/accounts/pollingDriftClientAccountSubscriber.js +2 -2
- package/lib/accounts/webSocketDriftClientAccountSubscriber.js +1 -1
- package/lib/addresses/pda.d.ts +1 -0
- package/lib/addresses/pda.js +8 -1
- package/lib/adminClient.d.ts +2 -0
- package/lib/adminClient.js +30 -0
- package/lib/constants/perpMarkets.js +10 -10
- package/lib/driftClient.d.ts +2 -0
- package/lib/driftClient.js +19 -1
- package/lib/factory/oracleClient.d.ts +2 -1
- package/lib/factory/oracleClient.js +5 -1
- package/lib/idl/drift.json +255 -35
- package/lib/oracles/oracleClientCache.d.ts +2 -1
- package/lib/oracles/oracleClientCache.js +2 -2
- package/lib/oracles/prelaunchOracleClient.d.ts +11 -0
- package/lib/oracles/prelaunchOracleClient.js +23 -0
- package/lib/types.d.ts +11 -0
- package/lib/types.js +1 -0
- package/package.json +1 -1
- package/src/accounts/pollingDriftClientAccountSubscriber.ts +4 -2
- package/src/accounts/webSocketDriftClientAccountSubscriber.ts +2 -1
- package/src/addresses/pda.ts +13 -0
- package/src/adminClient.ts +47 -0
- package/src/constants/perpMarkets.ts +10 -10
- package/src/driftClient.ts +36 -1
- package/src/factory/oracleClient.ts +8 -2
- package/src/idl/drift.json +255 -35
- package/src/oracles/oracleClientCache.ts +7 -2
- package/src/oracles/prelaunchOracleClient.ts +36 -0
- package/src/types.ts +10 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.71.0-beta.
|
|
1
|
+
2.71.0-beta.2
|
|
@@ -161,7 +161,7 @@ class PollingDriftClientAccountSubscriber {
|
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
163
|
async addOracleToAccountLoader(oracleToPoll) {
|
|
164
|
-
const oracleClient = this.oracleClientCache.get(oracleToPoll.source, this.program.provider.connection);
|
|
164
|
+
const oracleClient = this.oracleClientCache.get(oracleToPoll.source, this.program.provider.connection, this.program);
|
|
165
165
|
oracleToPoll.callbackId = await this.accountLoader.addAccount(oracleToPoll.publicKey, (buffer, slot) => {
|
|
166
166
|
if (!buffer)
|
|
167
167
|
return;
|
|
@@ -198,7 +198,7 @@ class PollingDriftClientAccountSubscriber {
|
|
|
198
198
|
for (const [_, oracleToPoll] of this.oraclesToPoll) {
|
|
199
199
|
const { buffer, slot } = this.accountLoader.getBufferAndSlot(oracleToPoll.publicKey);
|
|
200
200
|
if (buffer) {
|
|
201
|
-
const oracleClient = this.oracleClientCache.get(oracleToPoll.source, this.program.provider.connection);
|
|
201
|
+
const oracleClient = this.oracleClientCache.get(oracleToPoll.source, this.program.provider.connection, this.program);
|
|
202
202
|
const oraclePriceData = oracleClient.getOraclePriceDataFromBuffer(buffer);
|
|
203
203
|
this.oracles.set(oracleToPoll.publicKey.toString(), {
|
|
204
204
|
data: oraclePriceData,
|
|
@@ -107,7 +107,7 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
107
107
|
return true;
|
|
108
108
|
}
|
|
109
109
|
async subscribeToOracle(oracleInfo) {
|
|
110
|
-
const client = this.oracleClientCache.get(oracleInfo.source, this.program.provider.connection);
|
|
110
|
+
const client = this.oracleClientCache.get(oracleInfo.source, this.program.provider.connection, this.program);
|
|
111
111
|
const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('oracle', this.program, oracleInfo.publicKey, (buffer) => {
|
|
112
112
|
return client.getOraclePriceDataFromBuffer(buffer);
|
|
113
113
|
}, this.resubTimeoutMs, this.commitment);
|
package/lib/addresses/pda.d.ts
CHANGED
|
@@ -19,3 +19,4 @@ export declare function getSerumFulfillmentConfigPublicKey(programId: PublicKey,
|
|
|
19
19
|
export declare function getPhoenixFulfillmentConfigPublicKey(programId: PublicKey, market: PublicKey): PublicKey;
|
|
20
20
|
export declare function getReferrerNamePublicKeySync(programId: PublicKey, nameBuffer: number[]): PublicKey;
|
|
21
21
|
export declare function getProtocolIfSharesTransferConfigPublicKey(programId: PublicKey): PublicKey;
|
|
22
|
+
export declare function getPrelaunchOraclePublicKey(programId: PublicKey, marketIndex: number): PublicKey;
|
package/lib/addresses/pda.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.getProtocolIfSharesTransferConfigPublicKey = exports.getReferrerNamePublicKeySync = exports.getPhoenixFulfillmentConfigPublicKey = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
|
|
26
|
+
exports.getPrelaunchOraclePublicKey = exports.getProtocolIfSharesTransferConfigPublicKey = exports.getReferrerNamePublicKeySync = exports.getPhoenixFulfillmentConfigPublicKey = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
|
|
27
27
|
const web3_js_1 = require("@solana/web3.js");
|
|
28
28
|
const anchor = __importStar(require("@coral-xyz/anchor"));
|
|
29
29
|
async function getDriftStateAccountPublicKeyAndNonce(programId) {
|
|
@@ -137,3 +137,10 @@ function getProtocolIfSharesTransferConfigPublicKey(programId) {
|
|
|
137
137
|
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(anchor.utils.bytes.utf8.encode('if_shares_transfer_config'))], programId)[0];
|
|
138
138
|
}
|
|
139
139
|
exports.getProtocolIfSharesTransferConfigPublicKey = getProtocolIfSharesTransferConfigPublicKey;
|
|
140
|
+
function getPrelaunchOraclePublicKey(programId, marketIndex) {
|
|
141
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
142
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('prelaunch_oracle')),
|
|
143
|
+
new anchor.BN(marketIndex).toArrayLike(Buffer, 'le', 2),
|
|
144
|
+
], programId)[0];
|
|
145
|
+
}
|
|
146
|
+
exports.getPrelaunchOraclePublicKey = getPrelaunchOraclePublicKey;
|
package/lib/adminClient.d.ts
CHANGED
|
@@ -81,4 +81,6 @@ export declare class AdminClient extends DriftClient {
|
|
|
81
81
|
updateSpotMarketLiquidationFee(spotMarketIndex: number, liquidatorFee: number, ifLiquidationFee: number): Promise<TransactionSignature>;
|
|
82
82
|
initializeProtocolIfSharesTransferConfig(): Promise<TransactionSignature>;
|
|
83
83
|
updateProtocolIfSharesTransferConfig(whitelistedSigners?: PublicKey[], maxTransferPerEpoch?: BN): Promise<TransactionSignature>;
|
|
84
|
+
initializePrelaunchOracle(perpMarketIndex: number, price?: BN, maxPrice?: BN): Promise<TransactionSignature>;
|
|
85
|
+
updatePrelaunchOracleParams(perpMarketIndex: number, price?: BN, maxPrice?: BN): Promise<TransactionSignature>;
|
|
84
86
|
}
|
package/lib/adminClient.js
CHANGED
|
@@ -928,5 +928,35 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
928
928
|
},
|
|
929
929
|
});
|
|
930
930
|
}
|
|
931
|
+
async initializePrelaunchOracle(perpMarketIndex, price, maxPrice) {
|
|
932
|
+
const params = {
|
|
933
|
+
perpMarketIndex,
|
|
934
|
+
price: price || null,
|
|
935
|
+
maxPrice: maxPrice || null,
|
|
936
|
+
};
|
|
937
|
+
return await this.program.rpc.initializePrelaunchOracle(params, {
|
|
938
|
+
accounts: {
|
|
939
|
+
admin: this.wallet.publicKey,
|
|
940
|
+
state: await this.getStatePublicKey(),
|
|
941
|
+
prelaunchOracle: await (0, pda_1.getPrelaunchOraclePublicKey)(this.program.programId, perpMarketIndex),
|
|
942
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
943
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
944
|
+
},
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
async updatePrelaunchOracleParams(perpMarketIndex, price, maxPrice) {
|
|
948
|
+
const params = {
|
|
949
|
+
perpMarketIndex,
|
|
950
|
+
price: price || null,
|
|
951
|
+
maxPrice: maxPrice || null,
|
|
952
|
+
};
|
|
953
|
+
return await this.program.rpc.updatePrelaunchOracleParams(params, {
|
|
954
|
+
accounts: {
|
|
955
|
+
admin: this.wallet.publicKey,
|
|
956
|
+
state: await this.getStatePublicKey(),
|
|
957
|
+
prelaunchOracle: await (0, pda_1.getPrelaunchOraclePublicKey)(this.program.programId, perpMarketIndex),
|
|
958
|
+
},
|
|
959
|
+
});
|
|
960
|
+
}
|
|
931
961
|
}
|
|
932
962
|
exports.AdminClient = AdminClient;
|
|
@@ -234,16 +234,16 @@ exports.DevnetPerpMarkets = [
|
|
|
234
234
|
launchTs: 1704209558000,
|
|
235
235
|
oracleSource: __1.OracleSource.PYTH,
|
|
236
236
|
},
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
237
|
+
{
|
|
238
|
+
fullName: 'Wormhole',
|
|
239
|
+
category: ['Bridge'],
|
|
240
|
+
symbol: 'W-PERP',
|
|
241
|
+
baseAssetSymbol: 'W',
|
|
242
|
+
marketIndex: 23,
|
|
243
|
+
oracle: new web3_js_1.PublicKey('BM2UWqREbt7ktsPCA438dqAVqhU7UZFVg11CQyPXFr49'),
|
|
244
|
+
launchTs: 1709852537000,
|
|
245
|
+
oracleSource: __1.OracleSource.Prelaunch,
|
|
246
|
+
},
|
|
247
247
|
];
|
|
248
248
|
exports.MainnetPerpMarkets = [
|
|
249
249
|
{
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -600,6 +600,8 @@ export declare class DriftClient {
|
|
|
600
600
|
getResolveSpotBankruptcyIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, liquidatorSubAccountId?: number): Promise<TransactionInstruction>;
|
|
601
601
|
updateFundingRate(perpMarketIndex: number, oracle: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
|
|
602
602
|
getUpdateFundingRateIx(perpMarketIndex: number, oracle: PublicKey): Promise<TransactionInstruction>;
|
|
603
|
+
updatePrelaunchOracle(perpMarketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
604
|
+
getUpdatePrelaunchOracleIx(perpMarketIndex: number): Promise<TransactionInstruction>;
|
|
603
605
|
updatePerpBidAskTwap(perpMarketIndex: number, makers: [PublicKey, PublicKey][], txParams?: TxParams): Promise<TransactionSignature>;
|
|
604
606
|
getUpdatePerpBidAskTwapIx(perpMarketIndex: number, makers: [PublicKey, PublicKey][]): Promise<TransactionInstruction>;
|
|
605
607
|
settleFundingPayment(userAccountPublicKey: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
|
package/lib/driftClient.js
CHANGED
|
@@ -924,10 +924,11 @@ class DriftClient {
|
|
|
924
924
|
isSigner: false,
|
|
925
925
|
isWritable: writable,
|
|
926
926
|
});
|
|
927
|
+
const oracleWritable = writable && (0, types_1.isVariant)(perpMarketAccount.amm.oracleSource, 'prelaunch');
|
|
927
928
|
oracleAccountMap.set(perpMarketAccount.amm.oracle.toString(), {
|
|
928
929
|
pubkey: perpMarketAccount.amm.oracle,
|
|
929
930
|
isSigner: false,
|
|
930
|
-
isWritable:
|
|
931
|
+
isWritable: oracleWritable,
|
|
931
932
|
});
|
|
932
933
|
this.addSpotMarketToRemainingAccountMaps(perpMarketAccount.quoteSpotMarketIndex, false, oracleAccountMap, spotMarketAccountMap);
|
|
933
934
|
}
|
|
@@ -3117,6 +3118,23 @@ class DriftClient {
|
|
|
3117
3118
|
},
|
|
3118
3119
|
});
|
|
3119
3120
|
}
|
|
3121
|
+
async updatePrelaunchOracle(perpMarketIndex, txParams) {
|
|
3122
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getUpdatePrelaunchOracleIx(perpMarketIndex), txParams), [], this.opts);
|
|
3123
|
+
return txSig;
|
|
3124
|
+
}
|
|
3125
|
+
async getUpdatePrelaunchOracleIx(perpMarketIndex) {
|
|
3126
|
+
const perpMarket = this.getPerpMarketAccount(perpMarketIndex);
|
|
3127
|
+
if (!(0, types_1.isVariant)(perpMarket.amm.oracleSource, 'prelaunch')) {
|
|
3128
|
+
throw new Error(`Wrong oracle source ${perpMarket.amm.oracleSource}`);
|
|
3129
|
+
}
|
|
3130
|
+
return await this.program.instruction.updatePrelaunchOracle({
|
|
3131
|
+
accounts: {
|
|
3132
|
+
state: await this.getStatePublicKey(),
|
|
3133
|
+
perpMarket: perpMarket.pubkey,
|
|
3134
|
+
oracle: perpMarket.amm.oracle,
|
|
3135
|
+
},
|
|
3136
|
+
});
|
|
3137
|
+
}
|
|
3120
3138
|
async updatePerpBidAskTwap(perpMarketIndex, makers, txParams) {
|
|
3121
3139
|
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getUpdatePerpBidAskTwapIx(perpMarketIndex, makers), txParams), [], this.opts);
|
|
3122
3140
|
return txSig;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { OracleSource } from '../types';
|
|
2
2
|
import { Connection } from '@solana/web3.js';
|
|
3
3
|
import { OracleClient } from '../oracles/types';
|
|
4
|
-
|
|
4
|
+
import { Program } from '@coral-xyz/anchor';
|
|
5
|
+
export declare function getOracleClient(oracleSource: OracleSource, connection: Connection, program: Program): OracleClient;
|
|
@@ -6,7 +6,8 @@ const pythClient_1 = require("../oracles/pythClient");
|
|
|
6
6
|
// import { SwitchboardClient } from '../oracles/switchboardClient';
|
|
7
7
|
const quoteAssetOracleClient_1 = require("../oracles/quoteAssetOracleClient");
|
|
8
8
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
9
|
-
|
|
9
|
+
const prelaunchOracleClient_1 = require("../oracles/prelaunchOracleClient");
|
|
10
|
+
function getOracleClient(oracleSource, connection, program) {
|
|
10
11
|
if ((0, types_1.isVariant)(oracleSource, 'pyth')) {
|
|
11
12
|
return new pythClient_1.PythClient(connection);
|
|
12
13
|
}
|
|
@@ -22,6 +23,9 @@ function getOracleClient(oracleSource, connection) {
|
|
|
22
23
|
// if (isVariant(oracleSource, 'switchboard')) {
|
|
23
24
|
// return new SwitchboardClient(connection);
|
|
24
25
|
// }
|
|
26
|
+
if ((0, types_1.isVariant)(oracleSource, 'prelaunch')) {
|
|
27
|
+
return new prelaunchOracleClient_1.PrelaunchOracleClient(connection, program);
|
|
28
|
+
}
|
|
25
29
|
if ((0, types_1.isVariant)(oracleSource, 'quoteAsset')) {
|
|
26
30
|
return new quoteAssetOracleClient_1.QuoteAssetOracleClient();
|
|
27
31
|
}
|