@drift-labs/sdk 2.87.0-beta.2 → 2.87.0-beta.4
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/adminClient.js +1 -3
- package/lib/driftClient.d.ts +6 -0
- package/lib/driftClient.js +39 -0
- package/lib/factory/oracleClient.js +4 -0
- package/lib/idl/drift.json +3 -0
- package/lib/idl/switchboard_on_demand_30.json +4383 -0
- package/lib/math/superStake.d.ts +3 -2
- package/lib/oracles/switchboardOnDemandClient.d.ts +11 -0
- package/lib/oracles/switchboardOnDemandClient.js +32 -0
- package/lib/types.d.ts +3 -0
- package/lib/types.js +1 -0
- package/package.json +3 -1
- package/src/adminClient.ts +1 -3
- package/src/driftClient.ts +57 -0
- package/src/factory/oracleClient.ts +5 -0
- package/src/idl/drift.json +3 -0
- package/src/idl/switchboard_on_demand_30.json +4383 -0
- package/src/oracles/switchboardOnDemandClient.ts +56 -0
- package/src/types.ts +1 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.87.0-beta.
|
|
1
|
+
2.87.0-beta.4
|
package/lib/adminClient.js
CHANGED
|
@@ -484,9 +484,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
484
484
|
netUnsettledFundingPnl: netUnsettledFundingPnl !== null && netUnsettledFundingPnl !== void 0 ? netUnsettledFundingPnl : null,
|
|
485
485
|
}, {
|
|
486
486
|
accounts: {
|
|
487
|
-
admin: this.
|
|
488
|
-
? this.getStateAccount().admin
|
|
489
|
-
: this.wallet.publicKey,
|
|
487
|
+
admin: this.wallet.publicKey,
|
|
490
488
|
state: await this.getStatePublicKey(),
|
|
491
489
|
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
492
490
|
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, numericConstants_1.QUOTE_SPOT_MARKET_INDEX),
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/// <reference types="bn.js" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
|
|
5
|
+
import { Idl as Idl30, Program as Program30 } from '@coral-xyz/anchor-30';
|
|
5
6
|
import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, ReferrerNameAccount, OrderTriggerCondition, PerpMarketExtendedInfo, UserStatsAccount, PhoenixV1FulfillmentConfigAccount, ModifyOrderPolicy, SwapReduceOnly, SettlePnlMode, SignedTxData, MappedRecord, OpenbookV2FulfillmentConfigAccount } from './types';
|
|
6
7
|
import * as anchor from '@coral-xyz/anchor';
|
|
7
8
|
import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta, Signer, AddressLookupTableAccount, TransactionVersion, VersionedTransaction, BlockhashWithExpiryBlockHeight } from '@solana/web3.js';
|
|
@@ -65,6 +66,8 @@ export declare class DriftClient {
|
|
|
65
66
|
txHandler: TxHandler;
|
|
66
67
|
receiverProgram?: Program<PythSolanaReceiver>;
|
|
67
68
|
wormholeProgram?: Program<WormholeCoreBridgeSolana>;
|
|
69
|
+
sbOnDemandProgram?: Program30<Idl30>;
|
|
70
|
+
sbProgramFeedConfigs?: Map<string, any>;
|
|
68
71
|
get isSubscribed(): boolean;
|
|
69
72
|
set isSubscribed(val: boolean);
|
|
70
73
|
constructor(config: DriftClientConfig);
|
|
@@ -714,6 +717,7 @@ export declare class DriftClient {
|
|
|
714
717
|
marketType: MarketType;
|
|
715
718
|
} | undefined;
|
|
716
719
|
getReceiverProgram(): Program<PythSolanaReceiver>;
|
|
720
|
+
getSwitchboardOnDemandProgram(): Program30<Idl30>;
|
|
717
721
|
postPythPullOracleUpdateAtomic(vaaString: string, feedId: string): Promise<TransactionSignature>;
|
|
718
722
|
postMultiPythPullOracleUpdatesAtomic(vaaString: string, feedIds: string[]): Promise<TransactionSignature>;
|
|
719
723
|
getPostPythPullOracleUpdateAtomicIxs(vaaString: string, feedIds: string | string[], numSignatures?: number): Promise<TransactionInstruction[]>;
|
|
@@ -725,6 +729,8 @@ export declare class DriftClient {
|
|
|
725
729
|
proof: number[][];
|
|
726
730
|
};
|
|
727
731
|
}, feedId: string, encodedVaaAddress: PublicKey): Promise<TransactionInstruction>;
|
|
732
|
+
getPostSwitchboardOnDemandUpdateAtomicIx(feed: PublicKey, numSignatures?: number): Promise<TransactionInstruction | undefined>;
|
|
733
|
+
postSwitchboardOnDemandUpdate(feed: PublicKey, numSignatures?: number): Promise<TransactionSignature>;
|
|
728
734
|
private getBuildEncodedVaaIxs;
|
|
729
735
|
private handleSignedTransaction;
|
|
730
736
|
private handlePreSignedTransaction;
|
package/lib/driftClient.js
CHANGED
|
@@ -28,6 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.DriftClient = void 0;
|
|
30
30
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
31
|
+
const anchor_30_1 = require("@coral-xyz/anchor-30");
|
|
31
32
|
const bs58_1 = __importDefault(require("bs58"));
|
|
32
33
|
const spl_token_1 = require("@solana/spl-token");
|
|
33
34
|
const types_1 = require("./types");
|
|
@@ -65,6 +66,8 @@ const config_2 = require("./config");
|
|
|
65
66
|
const pythPullOracleUtils_1 = require("./util/pythPullOracleUtils");
|
|
66
67
|
const utils_2 = require("./tx/utils");
|
|
67
68
|
const pyth_solana_receiver_json_1 = __importDefault(require("./idl/pyth_solana_receiver.json"));
|
|
69
|
+
const on_demand_1 = require("@switchboard-xyz/on-demand");
|
|
70
|
+
const switchboard_on_demand_30_json_1 = __importDefault(require("./idl/switchboard_on_demand_30.json"));
|
|
68
71
|
/**
|
|
69
72
|
* # DriftClient
|
|
70
73
|
* This class is the main way to interact with Drift Protocol. It allows you to subscribe to the various accounts where the Market's state is stored, as well as: opening positions, liquidating, settling funding, depositing & withdrawing, and more.
|
|
@@ -3751,6 +3754,12 @@ class DriftClient {
|
|
|
3751
3754
|
}
|
|
3752
3755
|
return this.receiverProgram;
|
|
3753
3756
|
}
|
|
3757
|
+
getSwitchboardOnDemandProgram() {
|
|
3758
|
+
if (this.sbOnDemandProgram === undefined) {
|
|
3759
|
+
this.sbOnDemandProgram = new anchor_30_1.Program(switchboard_on_demand_30_json_1.default, this.provider);
|
|
3760
|
+
}
|
|
3761
|
+
return this.sbOnDemandProgram;
|
|
3762
|
+
}
|
|
3754
3763
|
async postPythPullOracleUpdateAtomic(vaaString, feedId) {
|
|
3755
3764
|
const postIxs = await this.getPostPythPullOracleUpdateAtomicIxs(vaaString, feedId);
|
|
3756
3765
|
const tx = await this.buildTransaction(postIxs);
|
|
@@ -3845,6 +3854,36 @@ class DriftClient {
|
|
|
3845
3854
|
},
|
|
3846
3855
|
});
|
|
3847
3856
|
}
|
|
3857
|
+
async getPostSwitchboardOnDemandUpdateAtomicIx(feed, numSignatures = 3) {
|
|
3858
|
+
const program = this.getSwitchboardOnDemandProgram();
|
|
3859
|
+
const feedAccount = new on_demand_1.PullFeed(program, feed);
|
|
3860
|
+
if (!this.sbProgramFeedConfigs) {
|
|
3861
|
+
this.sbProgramFeedConfigs = new Map();
|
|
3862
|
+
}
|
|
3863
|
+
if (!this.sbProgramFeedConfigs.has(feedAccount.pubkey.toString())) {
|
|
3864
|
+
const feedConfig = await feedAccount.loadConfigs();
|
|
3865
|
+
this.sbProgramFeedConfigs.set(feed.toString(), feedConfig);
|
|
3866
|
+
}
|
|
3867
|
+
const [pullIx, _responses, success] = await feedAccount.fetchUpdateIx({
|
|
3868
|
+
numSignatures,
|
|
3869
|
+
feedConfigs: this.sbProgramFeedConfigs.get(feed.toString()),
|
|
3870
|
+
});
|
|
3871
|
+
if (!success) {
|
|
3872
|
+
return undefined;
|
|
3873
|
+
}
|
|
3874
|
+
return pullIx;
|
|
3875
|
+
}
|
|
3876
|
+
async postSwitchboardOnDemandUpdate(feed, numSignatures = 3) {
|
|
3877
|
+
const pullIx = await this.getPostSwitchboardOnDemandUpdateAtomicIx(feed, numSignatures);
|
|
3878
|
+
if (!pullIx) {
|
|
3879
|
+
return undefined;
|
|
3880
|
+
}
|
|
3881
|
+
const tx = await this.buildTransaction(pullIx, undefined, 0, [
|
|
3882
|
+
await this.fetchMarketLookupTableAccount(),
|
|
3883
|
+
]);
|
|
3884
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
3885
|
+
return txSig;
|
|
3886
|
+
}
|
|
3848
3887
|
async getBuildEncodedVaaIxs(vaa, guardianSet) {
|
|
3849
3888
|
const postIxs = [];
|
|
3850
3889
|
if (this.wormholeProgram === undefined) {
|
|
@@ -9,6 +9,7 @@ const anchor_1 = require("@coral-xyz/anchor");
|
|
|
9
9
|
const prelaunchOracleClient_1 = require("../oracles/prelaunchOracleClient");
|
|
10
10
|
const switchboardClient_1 = require("../oracles/switchboardClient");
|
|
11
11
|
const pythPullClient_1 = require("../oracles/pythPullClient");
|
|
12
|
+
const switchboardOnDemandClient_1 = require("../oracles/switchboardOnDemandClient");
|
|
12
13
|
function getOracleClient(oracleSource, connection, program) {
|
|
13
14
|
if ((0, types_1.isVariant)(oracleSource, 'pyth')) {
|
|
14
15
|
return new pythClient_1.PythClient(connection);
|
|
@@ -43,6 +44,9 @@ function getOracleClient(oracleSource, connection, program) {
|
|
|
43
44
|
if ((0, types_1.isVariant)(oracleSource, 'quoteAsset')) {
|
|
44
45
|
return new quoteAssetOracleClient_1.QuoteAssetOracleClient();
|
|
45
46
|
}
|
|
47
|
+
if ((0, types_1.isVariant)(oracleSource, 'switchboardOnDemand')) {
|
|
48
|
+
return new switchboardOnDemandClient_1.SwitchboardOnDemandClient(connection);
|
|
49
|
+
}
|
|
46
50
|
throw new Error(`Unknown oracle source ${oracleSource}`);
|
|
47
51
|
}
|
|
48
52
|
exports.getOracleClient = getOracleClient;
|