@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/lib/types.d.ts
CHANGED
|
@@ -149,6 +149,9 @@ export declare class OracleSource {
|
|
|
149
149
|
static readonly PYTH_STABLE_COIN: {
|
|
150
150
|
pythStableCoin: {};
|
|
151
151
|
};
|
|
152
|
+
static readonly Prelaunch: {
|
|
153
|
+
prelaunch: {};
|
|
154
|
+
};
|
|
152
155
|
}
|
|
153
156
|
export declare class OrderType {
|
|
154
157
|
static readonly LIMIT: {
|
|
@@ -1084,6 +1087,14 @@ export type OracleGuardRails = {
|
|
|
1084
1087
|
tooVolatileRatio: BN;
|
|
1085
1088
|
};
|
|
1086
1089
|
};
|
|
1090
|
+
export type PrelaunchOracle = {
|
|
1091
|
+
price: BN;
|
|
1092
|
+
maxPrice: BN;
|
|
1093
|
+
confidence: BN;
|
|
1094
|
+
ammLastUpdateSlot: BN;
|
|
1095
|
+
lastUpdateSlot: BN;
|
|
1096
|
+
perpMarketIndex: number;
|
|
1097
|
+
};
|
|
1087
1098
|
export type MarginCategory = 'Initial' | 'Maintenance';
|
|
1088
1099
|
export type InsuranceFundStake = {
|
|
1089
1100
|
costBasis: BN;
|
package/lib/types.js
CHANGED
|
@@ -98,6 +98,7 @@ OracleSource.PYTH_1M = { pyth1M: {} };
|
|
|
98
98
|
// static readonly SWITCHBOARD = { switchboard: {} };
|
|
99
99
|
OracleSource.QUOTE_ASSET = { quoteAsset: {} };
|
|
100
100
|
OracleSource.PYTH_STABLE_COIN = { pythStableCoin: {} };
|
|
101
|
+
OracleSource.Prelaunch = { prelaunch: {} };
|
|
101
102
|
class OrderType {
|
|
102
103
|
}
|
|
103
104
|
exports.OrderType = OrderType;
|
package/package.json
CHANGED
|
@@ -257,7 +257,8 @@ export class PollingDriftClientAccountSubscriber
|
|
|
257
257
|
async addOracleToAccountLoader(oracleToPoll: OraclesToPoll): Promise<void> {
|
|
258
258
|
const oracleClient = this.oracleClientCache.get(
|
|
259
259
|
oracleToPoll.source,
|
|
260
|
-
this.program.provider.connection
|
|
260
|
+
this.program.provider.connection,
|
|
261
|
+
this.program
|
|
261
262
|
);
|
|
262
263
|
|
|
263
264
|
oracleToPoll.callbackId = await this.accountLoader.addAccount(
|
|
@@ -316,7 +317,8 @@ export class PollingDriftClientAccountSubscriber
|
|
|
316
317
|
if (buffer) {
|
|
317
318
|
const oracleClient = this.oracleClientCache.get(
|
|
318
319
|
oracleToPoll.source,
|
|
319
|
-
this.program.provider.connection
|
|
320
|
+
this.program.provider.connection,
|
|
321
|
+
this.program
|
|
320
322
|
);
|
|
321
323
|
const oraclePriceData =
|
|
322
324
|
oracleClient.getOraclePriceDataFromBuffer(buffer);
|
|
@@ -204,7 +204,8 @@ export class WebSocketDriftClientAccountSubscriber
|
|
|
204
204
|
async subscribeToOracle(oracleInfo: OracleInfo): Promise<boolean> {
|
|
205
205
|
const client = this.oracleClientCache.get(
|
|
206
206
|
oracleInfo.source,
|
|
207
|
-
this.program.provider.connection
|
|
207
|
+
this.program.provider.connection,
|
|
208
|
+
this.program
|
|
208
209
|
);
|
|
209
210
|
const accountSubscriber = new WebSocketAccountSubscriber<OraclePriceData>(
|
|
210
211
|
'oracle',
|
package/src/addresses/pda.ts
CHANGED
|
@@ -223,3 +223,16 @@ export function getProtocolIfSharesTransferConfigPublicKey(
|
|
|
223
223
|
programId
|
|
224
224
|
)[0];
|
|
225
225
|
}
|
|
226
|
+
|
|
227
|
+
export function getPrelaunchOraclePublicKey(
|
|
228
|
+
programId: PublicKey,
|
|
229
|
+
marketIndex: number
|
|
230
|
+
): PublicKey {
|
|
231
|
+
return PublicKey.findProgramAddressSync(
|
|
232
|
+
[
|
|
233
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('prelaunch_oracle')),
|
|
234
|
+
new anchor.BN(marketIndex).toArrayLike(Buffer, 'le', 2),
|
|
235
|
+
],
|
|
236
|
+
programId
|
|
237
|
+
)[0];
|
|
238
|
+
}
|
package/src/adminClient.ts
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
getSerumFulfillmentConfigPublicKey,
|
|
27
27
|
getPhoenixFulfillmentConfigPublicKey,
|
|
28
28
|
getProtocolIfSharesTransferConfigPublicKey,
|
|
29
|
+
getPrelaunchOraclePublicKey,
|
|
29
30
|
} from './addresses/pda';
|
|
30
31
|
import { squareRootBN } from './math/utils';
|
|
31
32
|
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
@@ -1794,4 +1795,50 @@ export class AdminClient extends DriftClient {
|
|
|
1794
1795
|
}
|
|
1795
1796
|
);
|
|
1796
1797
|
}
|
|
1798
|
+
|
|
1799
|
+
public async initializePrelaunchOracle(
|
|
1800
|
+
perpMarketIndex: number,
|
|
1801
|
+
price?: BN,
|
|
1802
|
+
maxPrice?: BN
|
|
1803
|
+
): Promise<TransactionSignature> {
|
|
1804
|
+
const params = {
|
|
1805
|
+
perpMarketIndex,
|
|
1806
|
+
price: price || null,
|
|
1807
|
+
maxPrice: maxPrice || null,
|
|
1808
|
+
};
|
|
1809
|
+
return await this.program.rpc.initializePrelaunchOracle(params, {
|
|
1810
|
+
accounts: {
|
|
1811
|
+
admin: this.wallet.publicKey,
|
|
1812
|
+
state: await this.getStatePublicKey(),
|
|
1813
|
+
prelaunchOracle: await getPrelaunchOraclePublicKey(
|
|
1814
|
+
this.program.programId,
|
|
1815
|
+
perpMarketIndex
|
|
1816
|
+
),
|
|
1817
|
+
rent: SYSVAR_RENT_PUBKEY,
|
|
1818
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
1819
|
+
},
|
|
1820
|
+
});
|
|
1821
|
+
}
|
|
1822
|
+
|
|
1823
|
+
public async updatePrelaunchOracleParams(
|
|
1824
|
+
perpMarketIndex: number,
|
|
1825
|
+
price?: BN,
|
|
1826
|
+
maxPrice?: BN
|
|
1827
|
+
): Promise<TransactionSignature> {
|
|
1828
|
+
const params = {
|
|
1829
|
+
perpMarketIndex,
|
|
1830
|
+
price: price || null,
|
|
1831
|
+
maxPrice: maxPrice || null,
|
|
1832
|
+
};
|
|
1833
|
+
return await this.program.rpc.updatePrelaunchOracleParams(params, {
|
|
1834
|
+
accounts: {
|
|
1835
|
+
admin: this.wallet.publicKey,
|
|
1836
|
+
state: await this.getStatePublicKey(),
|
|
1837
|
+
prelaunchOracle: await getPrelaunchOraclePublicKey(
|
|
1838
|
+
this.program.programId,
|
|
1839
|
+
perpMarketIndex
|
|
1840
|
+
),
|
|
1841
|
+
},
|
|
1842
|
+
});
|
|
1843
|
+
}
|
|
1797
1844
|
}
|
|
@@ -244,16 +244,16 @@ export const DevnetPerpMarkets: PerpMarketConfig[] = [
|
|
|
244
244
|
launchTs: 1704209558000,
|
|
245
245
|
oracleSource: OracleSource.PYTH,
|
|
246
246
|
},
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
247
|
+
{
|
|
248
|
+
fullName: 'Wormhole',
|
|
249
|
+
category: ['Bridge'],
|
|
250
|
+
symbol: 'W-PERP',
|
|
251
|
+
baseAssetSymbol: 'W',
|
|
252
|
+
marketIndex: 23,
|
|
253
|
+
oracle: new PublicKey('BM2UWqREbt7ktsPCA438dqAVqhU7UZFVg11CQyPXFr49'),
|
|
254
|
+
launchTs: 1709852537000,
|
|
255
|
+
oracleSource: OracleSource.Prelaunch,
|
|
256
|
+
},
|
|
257
257
|
];
|
|
258
258
|
|
|
259
259
|
export const MainnetPerpMarkets: PerpMarketConfig[] = [
|
package/src/driftClient.ts
CHANGED
|
@@ -1566,10 +1566,12 @@ export class DriftClient {
|
|
|
1566
1566
|
isSigner: false,
|
|
1567
1567
|
isWritable: writable,
|
|
1568
1568
|
});
|
|
1569
|
+
const oracleWritable =
|
|
1570
|
+
writable && isVariant(perpMarketAccount.amm.oracleSource, 'prelaunch');
|
|
1569
1571
|
oracleAccountMap.set(perpMarketAccount.amm.oracle.toString(), {
|
|
1570
1572
|
pubkey: perpMarketAccount.amm.oracle,
|
|
1571
1573
|
isSigner: false,
|
|
1572
|
-
isWritable:
|
|
1574
|
+
isWritable: oracleWritable,
|
|
1573
1575
|
});
|
|
1574
1576
|
this.addSpotMarketToRemainingAccountMaps(
|
|
1575
1577
|
perpMarketAccount.quoteSpotMarketIndex,
|
|
@@ -5787,6 +5789,39 @@ export class DriftClient {
|
|
|
5787
5789
|
});
|
|
5788
5790
|
}
|
|
5789
5791
|
|
|
5792
|
+
public async updatePrelaunchOracle(
|
|
5793
|
+
perpMarketIndex: number,
|
|
5794
|
+
txParams?: TxParams
|
|
5795
|
+
): Promise<TransactionSignature> {
|
|
5796
|
+
const { txSig } = await this.sendTransaction(
|
|
5797
|
+
await this.buildTransaction(
|
|
5798
|
+
await this.getUpdatePrelaunchOracleIx(perpMarketIndex),
|
|
5799
|
+
txParams
|
|
5800
|
+
),
|
|
5801
|
+
[],
|
|
5802
|
+
this.opts
|
|
5803
|
+
);
|
|
5804
|
+
return txSig;
|
|
5805
|
+
}
|
|
5806
|
+
|
|
5807
|
+
public async getUpdatePrelaunchOracleIx(
|
|
5808
|
+
perpMarketIndex: number
|
|
5809
|
+
): Promise<TransactionInstruction> {
|
|
5810
|
+
const perpMarket = this.getPerpMarketAccount(perpMarketIndex);
|
|
5811
|
+
|
|
5812
|
+
if (!isVariant(perpMarket.amm.oracleSource, 'prelaunch')) {
|
|
5813
|
+
throw new Error(`Wrong oracle source ${perpMarket.amm.oracleSource}`);
|
|
5814
|
+
}
|
|
5815
|
+
|
|
5816
|
+
return await this.program.instruction.updatePrelaunchOracle({
|
|
5817
|
+
accounts: {
|
|
5818
|
+
state: await this.getStatePublicKey(),
|
|
5819
|
+
perpMarket: perpMarket.pubkey,
|
|
5820
|
+
oracle: perpMarket.amm.oracle,
|
|
5821
|
+
},
|
|
5822
|
+
});
|
|
5823
|
+
}
|
|
5824
|
+
|
|
5790
5825
|
public async updatePerpBidAskTwap(
|
|
5791
5826
|
perpMarketIndex: number,
|
|
5792
5827
|
makers: [PublicKey, PublicKey][],
|
|
@@ -4,11 +4,13 @@ import { OracleClient } from '../oracles/types';
|
|
|
4
4
|
import { PythClient } from '../oracles/pythClient';
|
|
5
5
|
// import { SwitchboardClient } from '../oracles/switchboardClient';
|
|
6
6
|
import { QuoteAssetOracleClient } from '../oracles/quoteAssetOracleClient';
|
|
7
|
-
import { BN } from '@coral-xyz/anchor';
|
|
7
|
+
import { BN, Program } from '@coral-xyz/anchor';
|
|
8
|
+
import { PrelaunchOracleClient } from '../oracles/prelaunchOracleClient';
|
|
8
9
|
|
|
9
10
|
export function getOracleClient(
|
|
10
11
|
oracleSource: OracleSource,
|
|
11
|
-
connection: Connection
|
|
12
|
+
connection: Connection,
|
|
13
|
+
program: Program
|
|
12
14
|
): OracleClient {
|
|
13
15
|
if (isVariant(oracleSource, 'pyth')) {
|
|
14
16
|
return new PythClient(connection);
|
|
@@ -30,6 +32,10 @@ export function getOracleClient(
|
|
|
30
32
|
// return new SwitchboardClient(connection);
|
|
31
33
|
// }
|
|
32
34
|
|
|
35
|
+
if (isVariant(oracleSource, 'prelaunch')) {
|
|
36
|
+
return new PrelaunchOracleClient(connection, program);
|
|
37
|
+
}
|
|
38
|
+
|
|
33
39
|
if (isVariant(oracleSource, 'quoteAsset')) {
|
|
34
40
|
return new QuoteAssetOracleClient();
|
|
35
41
|
}
|